IPB
Your Ad Here


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Nedd a little help with this preg_match()
Misha Singh
post Nov 6 2009, 10:28 AM
Post #1


Advanced Member
***

Group: Members
Posts: 7,885
Joined: 23-November 08
Member No.: 6,521



I am wanting to do a simple extraction of the
three key header elements from a web page namely these:


Quote:





<title>This the Title</title>
<meta name="keywords" content="PHP, javascript, other keywords" />
<meta name="description" content="This is the description." />





Is the preg_match() function the best way to find them and put them
into variables ?

If they are not found of the web page I would like to fill the relevant variable
ith "Not found".

I have wriiten this code but I am not sure if it is the best approach
or if the logic is correct.


PHP Code:





$title = preg_match("/<title>(.*?)</title>/",$text,$matches);

if (
$title === false) {

$title = "None found";

}


$descrip = preg_match("/<meta name="description" content="(.*?)"/",$text,$matches);

if (
$descrip === false) {

$descrip = "None found";

}


$keys = preg_match("/<meta name="keywords" content="(.*?)"/",$text,$matches);

if (
$keys === false) {

$keys = "None found";

}








Any suggestions, corrections most welcome. smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
Tags
No Tag inserted yet

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 21st November 2009 - 02:22 PM
Your Ad Here