Forum Moderators: coopster
Regular Expression Functions (POSIX Extended) [php.net]
Regular Expression Functions (Perl-Compatible) [php.net]
For example, you could read the LOCAL page by using this:
$filename = "thispage.html";
$file_handler = fopen($filename);
$webpage_contents = fread ($file_handler, filesize ($filename));
fclose($file_handler);
And I noticed a bug in the code. It is missing 1 thing. Beside \w, add \.\-\+ This will ensure those characters will be matched as well.
noSanity
preg_match [php.net]("'<title>([^<]*?)</title>'",
implode [php.net]('', file [php.net]('http://www.aaron.com/')),
$m);
$title = $m[1]
In PHP [php.net] 4.3+ you could save the implode [php.net] and do something like this:
preg_match [php.net]("'<title>([^<]*?)</title>'",
file_get_contents [php.net]('http://www.aaron.com/'),
$m);
$title = $m[1]
This will work even for Aaron.
<added>I just read that nosanity changed his code. However, the perfectly valid title of Aaron & Nick still would not match ;-)</added>
Andreas
So you are no longer trying to match the title but the body element?
>>preg_match("'/<\/head>([.*]*)Powered by <a href/'",
This will match /</head>, then greedily .* followed by Powered by <a href/. The slash before the closing head tag will never occur in valid HTML and neither will href followed by a slash.
The first sign of the pattern string is cnsidered the pattern delimiter. In this case it is the single quote. Not using the slash when matching html tags has the advantage that you do not have to escape the slash in your pattern. So it is always wise to choose a delimiter that is not in your pattern.
HTH Andreas
[webmasterworld.com...]