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. Quote 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 } ?> Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.