snk Posted December 10, 2007 Share Posted December 10, 2007 hello again, I want to make a name comparison of a string but I want to to not be stricted exactly on the string's name for example: if($a == "exactly"){...} if string is 1exactly2 then the statement will never be true. how can i make it true? thanks Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 you can use strpos Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 <?php $a = "this is exactly one string"; if (preg_match('/exactly/',$a)) { echo "found"; } else { echo "not found"; } ?> Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted December 10, 2007 Share Posted December 10, 2007 RegEx. Stands for Regular Expressions. http://www.google.com/search?channel=s&hl=en&q=RegEx+PHP&btnG=Google+Search Quote Link to comment Share on other sites More sharing options...
snk Posted December 10, 2007 Author Share Posted December 10, 2007 Yeap regex is the answer, thanks m8 Quote Link to comment Share on other sites More sharing options...
snk Posted December 10, 2007 Author Share Posted December 10, 2007 <?php $a = "this is exactly one string"; if (preg_match('/exactly/',$a)) { echo "found"; } else { echo "not found"; } ?> if exactly is value? how do i use it? i try if (preg_match('/$some_value/',$a)) and nothing happens. thanks Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 should be if (preg_match("/$some_value/",$a)) use double quotes instead of single quotes Quote Link to comment Share on other sites More sharing options...
snk Posted December 10, 2007 Author Share Posted December 10, 2007 i have if (preg_match("/$search_criteria/",$word[i])){ but it doesnt work.. can you see anything wrong with the [] of the second value or something else? thanks for your help, its my first time in regex and a have harsh times. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 please echo your $search_criteria and $word before that and let me know what it is echo $search_criteria; echo $word; if (preg_match("/$search_criteria/",$word)){ Quote Link to comment Share on other sites More sharing options...
snk Posted December 10, 2007 Author Share Posted December 10, 2007 sorry i edited the code, i have if (preg_match("/$search_criteria/",$word[i])){ sorry again, i didnt know that takes away the brackets if i dont put it in code tag Quote Link to comment Share on other sites More sharing options...
snk Posted December 10, 2007 Author Share Posted December 10, 2007 $search_criteria = $_POST('search_criteria'); //echoes whatever i put in my form correctly $str = file_get_contents("http://www.dcs.napier.ac.uk/~cs170/32037lnotes.html"); $word = explode(" ",$str); //echoes everything right Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 what exactly are you trying to achieve by this code ? Quote Link to comment Share on other sites More sharing options...
snk Posted December 10, 2007 Author Share Posted December 10, 2007 aaaaaxxxxx damn again i was forgoting to put $ in i at $word you were absolute right... "/$search_criteria/" works..! thank you.. and sorry for the troubles that i created with my stupid observation Quote Link to comment 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.