Welcome to WebmasterWorld Guest from 107.22.87.145

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Regex - extracting: intitle: intext: etc

     
3:57 pm on Jun 25, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 2, 2003
posts:95
votes: 0


I need some help extracting the text for intitle: intext: search functions.

for example:

$q = 'site:webmasterworld.com intitle:google adsense intext:contextual advertising';

Text to be extracted:

$val[intitle] = 'google adsense';
$val[intext] = 'contextual advertising';

I've tried lots of variants similar to:

$match[intitle] = '/(^¦ )intitle:?(.+)( intitle:¦ intext:)/i';

preg_match($match[intitle], $q, $varInTitle);

But I'm crap at regex... :( nothing is working the way I want.

Can anyone help?

Cheers

5:27 pm on June 25, 2005 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


$pattern = '/intitle:(.*)intext:(.*)/'; 
preg_match($pattern, $q, $matches);
list($wholematch, $intitle, $intext) = $matches;

Now you have two variables, $intitle and $intext containing the values.
7:38 pm on June 25, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 2, 2003
posts:95
votes: 0


Awesome mate, thats definetly pointed me in the right direction!

KUDOS