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 Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/ Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 you can use strpos Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410775 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410776 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 Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410781 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 Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410782 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 Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410795 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 Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410799 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. Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410804 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)){ Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410806 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 Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410807 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 Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410811 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 ? Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410830 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 Link to comment https://forums.phpfreaks.com/topic/80971-how-can-i-compaire-a-string-in-like-analogy-of-mysql/#findComment-410833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.