Re: stripping <title>Title</title> from page?
| From: | Michael Dearman | Date: | Mon, 11 Dec 2000 22:18:43 +0000 |
| Subject: | Re: stripping <title>Title</title> from page? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29754@lists.php.net to get a copy of this message | ||
Yoeri De Bruyn wrote:
>
> Hi,
>
> I want to retrieve the title from every page of my website, put it together
> with the URL of the page in a MySql database to setup a search engine.
>
> Next code is not very ecological (it takes about 30" to parse one html
> page)!!!
> Anybody a briliant clue on how I should tune this one?
>
> Thanks a lot for any handy trick!
> Yoeri.
>
> <?php
>
> function inString($start, $end,$string)
> {
> eregi(".*".$start."(.*)".$end.".*",$string,$result);
Using pregs seems to always be faster.
Note you'll have to escape the '/' when passing the
closing tag as $end argument to your function: '<\/title>
function inString($start, $end, $string) {
$pat="/.*". $start . "(.*)" . $end . ".*/i";
preg_match($pat, $string, $result);
}
> return($result[1]);
> }
>
You'll also seem some speed improvement by going through
the whole routine of getting to your file with fopen and
using fread. At least that's what my crude timer showed - suprisingly.
Mike D.
> $pageContent=implode(' ', file('test.html'));
> $title=inString("<title>","</title>",$pageContent);
>
> echo($title);
> ?>
>
> --
> 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