Re: fopen // eregi question

From: Date: Wed, 26 Sep 2001 14:46:59 +0000
Subject: Re: fopen // eregi question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-68873@lists.php.net to get a copy of this message
If you use preg_match (PERL style Regex) instead of ereg you can use the s match modifier which tells it to treat the entire file as a single line... so your Regex would be if (preg_match("|<title>(.*)</title>|is", $line, $out)) { (The i is case insensitive... since you were using eregi) Hope that helps Sheridan Saint-Michel Website Administrator FoxJet, an ITW Company www.foxjet.com ----- Original Message ----- From: "Brian V Bonini" <b-bonini@home.com> To: "PHP Lists" <php-general@lists.php.net> Sent: Wednesday, September 26, 2001 9:21 AM Subject: [PHP] fopen // eregi question > >From the PHP manual: > > http://www.php.net/manual/en/features.remote-files.php > > Example 20-1. Getting the title of a remote page > > <?php > $file = fopen ("http://www.php.net/", "r"); > if (!$file) { > echo "<p>Unable to open remote file.\n"; > exit; > } > while (!feof ($file)) { > $line = fgets ($file, 1024); > /* This only works if the title and its tags are on one line */ > if (eregi ("<title>(.*)</title>", $line, $out)) { > $title = $out[1]; > break; > } > } > fclose($file); > ?> > > How would you make this work if the tags and content > spanned several lines? > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#68873) next »