thebestone Posted June 3, 2007 Share Posted June 3, 2007 Hello everyone, I'm sure this is a pretty easy thing to do but since I'm pretty new at PHP, I'm not sure how to do it. Basically I want to search a page for words and if they are found I want the script to do one thing. If they're not found, I want it to do something else. If someone could point me in the right direction it'd be very appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/54056-finding-text-within-a-page/ Share on other sites More sharing options...
kael.shipman Posted June 3, 2007 Share Posted June 3, 2007 Load the contents of the page into a variable (I assume this is already done, but just in case....). Now use either strpos($haystack,$needle[,$offset]) to find it or use preg_match('/regExNeedle/', $haystack [, array &$matches [, PREG_OFFSET_CAPTURE [, int $offset]]]). Sorry for all the syntax, but now you don't have to look it up! Do this: <?php if (strpos($pageContents,$needle) !== false) { //Code to execute } else { //Default Code } //or if (preg_match($regExNeedle,$pageContents)) { //Code } else { //Default } ?> Link to comment https://forums.phpfreaks.com/topic/54056-finding-text-within-a-page/#findComment-267223 Share on other sites More sharing options...
thebestone Posted June 3, 2007 Author Share Posted June 3, 2007 Thanks, I got it working. Link to comment https://forums.phpfreaks.com/topic/54056-finding-text-within-a-page/#findComment-267240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.