Wildhalf Posted March 8, 2007 Share Posted March 8, 2007 Hi I have been looking it up but cant come up with the code to extract a word from a string. example : "Hi There I am Kieron" I want to extract "Kieron" It doesn't matter really if the returned value equals what i am looking for a True or False would do. But it would be handy if i could. Kieron Link to comment https://forums.phpfreaks.com/topic/41753-solved-php-extracting-a-word-from-a-string/ Share on other sites More sharing options...
flappy_warbucks Posted March 8, 2007 Share Posted March 8, 2007 $string = preg_match("/kieron/i",$source); that i think should do it for you. (the "i" is there so it isnt case sensitive) Link to comment https://forums.phpfreaks.com/topic/41753-solved-php-extracting-a-word-from-a-string/#findComment-202411 Share on other sites More sharing options...
paul2463 Posted March 8, 2007 Share Posted March 8, 2007 try this $string = "Hi There I am Kieron"; if (preg_match("/kieron/i", $string)) { // the i makes it an case insensitive search return true; } else { return false; } Link to comment https://forums.phpfreaks.com/topic/41753-solved-php-extracting-a-word-from-a-string/#findComment-202414 Share on other sites More sharing options...
Wildhalf Posted March 8, 2007 Author Share Posted March 8, 2007 Thanks for your replys.... I just figured it out.... The following works for me I used ereg() <? $referrer = $_SERVER['HTTP_REFERER']; //echo "$referrer"; echo $referrer; echo '<br />'; ereg ("Kieron", $referrer, $domain); If ($domain[0] == 'Kieron'){ echo 'This works </br>'; } echo $domain[0]; // prints @example.com ?> Link to comment https://forums.phpfreaks.com/topic/41753-solved-php-extracting-a-word-from-a-string/#findComment-202418 Share on other sites More sharing options...
chrisuk Posted March 8, 2007 Share Posted March 8, 2007 this will work only if it find's keiron though, is this what you want? If not then you may want to look into using substr() Link to comment https://forums.phpfreaks.com/topic/41753-solved-php-extracting-a-word-from-a-string/#findComment-202426 Share on other sites More sharing options...
Wildhalf Posted March 8, 2007 Author Share Posted March 8, 2007 Is that going to be the same for anyway you do it?? Unless you create a variable. I am really using it to make sure my customers have paid me via paypal. For what i am doing i cannot encrypt my paypal subscription buttons (Im not going into why). Therefore my return URL will be displayed. I will search for the string "paypal.com" and with this code in place it checks to see if the server who sent the user there was paypal or not. If so it will display my signup/download link or else dispay an error message telling them they did not pay. Link to comment https://forums.phpfreaks.com/topic/41753-solved-php-extracting-a-word-from-a-string/#findComment-202431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.