Forum Moderators: coopster
$remote = fopen($url, 'r');
$html = fread($remote, 1048576);
fclose($remote);
preg_match("/<font face=\"Tahoma,Arial,Helvetica\" size=2><b>(.*)<\/b><\/font>/i", $var, $name);
$name = $name[1];
echo $name;
The variables just come back blank.
However if I take a section of the html and manually insert it into a variable and comment out the \”s it works.
I must be missing something but I cannot for the life of me figure it out.
Cheers
I'm not sure where the error is occurring but, it seem like what you have should work.
It could have something to do with this warning:
WarningWhen reading from network streams or pipes, such as those returned when reading remote files or from popen() and proc_open(), reading will stop after a packet is available. This means that you should collect the data together in chunks as shown in the example below.
fread() [php.net]
I also found this in the manual:
file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.
file_get_contents() [php.net]
Regards,
Birdman
Workout out it appears to be the fact that when I was testing I cut a small block of text to test locally. However that screwed my regex as the real version has line breaks and carriage returns. However when I remoev them with:
$var = ereg_replace("\n", "", $var);
$var = ereg_replace("\r", "", $var);
It somehow sucks the HTML code into the varible. Any ideas as what I am doing wrong.
Cheers
preg_match("/<font face=\\"Tahoma,Arial,Helvetica\\" size=2><b>(.*)<\/b><\/font>/i", $var, $name);
Or if that doesn't work:
preg_match("/<font face=\\\\"Tahoma,Arial,Helvetica\\\\" size=2><b>(.*)<\/b><\/font>/i", $var, $name);
Hopefully it'll work for you.