problem with preg_match to get title of current page
Posted: Sun Sep 05, 2010 2:53 pm
Hi,
I'm working on a script that creates another script. I have that part working, making another php file which includes a template.
The template needs to pull some data from the data base but needs to know the name of the program. The program name happens to be the title of the script that I created. So I am trying to use preg_match to have the script read it's self and find the title.
I'm getting the error, preg_match(): Compilation failed: nothing to repeat at offset 8
Here's my code.
I originally tried preg_match("/<title>(*)<\\\/title>/",fgets($fh,4096),$matches
which I think was supposed to escape the "/" before title but it gave me a undefined error for "t" so I decided to try the ascii code for "/"
Can anyone suggest what is causing the problem here?
Thanks
I'm working on a script that creates another script. I have that part working, making another php file which includes a template.
The template needs to pull some data from the data base but needs to know the name of the program. The program name happens to be the title of the script that I created. So I am trying to use preg_match to have the script read it's self and find the title.
I'm getting the error, preg_match(): Compilation failed: nothing to repeat at offset 8
Here's my code.
Code: Select all
//get account name from title tag set when program created
$fh = fopen($DOCUMENT_ROOT.$PHP_SELF,"r");
$found=false;
$title="";
$matches = "";
while(!feof($fh) && !$found){
if(preg_match("/<title>(*)</title>/",fgets($fh,4096),$matches)){
$found=true;
$title=$matches[1];
}
}
fclose($fh);
if($found){
// Here title is correct
echo $title;
}
else{
// this page doesn't contain <title>
}
which I think was supposed to escape the "/" before title but it gave me a undefined error for "t" so I decided to try the ascii code for "/"
Can anyone suggest what is causing the problem here?
Thanks