Nandini Posted August 29, 2008 Share Posted August 29, 2008 Hi all This is very good forum. I got so much solutions from this. I thank to all. ok my problem is i have a string like 111:[email protected]:5080/111 I want to know "/" is there in my string or not. I have to write some script if "/" is there in that string. So can any one give me preg_match to find that "/". Thanq Link to comment https://forums.phpfreaks.com/topic/121824-preg-match/ Share on other sites More sharing options...
JasonLewis Posted August 29, 2008 Share Posted August 29, 2008 Just use strpos(). $str = "111:[email protected]:5080/111"; if(strpos("/", $str)){ echo "It's in there!"; }else{ echo "Couldn't find it!"; } Link to comment https://forums.phpfreaks.com/topic/121824-preg-match/#findComment-628537 Share on other sites More sharing options...
DarkWater Posted August 29, 2008 Share Posted August 29, 2008 Actually, that's not how you are supposed to use strpos, ProjectFear. You need to do something like: $str = "111:[email protected]:5080/111"; if(strpos("/", $str) !== FALSE){ echo "It's in there!"; }else{ echo "Couldn't find it!"; } That's because if the character appears at the first position in the string, strpos() returns 0, and not FALSE, but it's still evaluated as FALSE unless you explicitly say otherwise. Link to comment https://forums.phpfreaks.com/topic/121824-preg-match/#findComment-628731 Share on other sites More sharing options...
nrg_alpha Posted August 29, 2008 Share Posted August 29, 2008 I think I would side with the function strpbrk: $str = "111:[email protected]:5080/111"; if(strpbrk($str, '/') == true){ echo "It's in there!"; } else { echo "Couldn't find it!"; } Link to comment https://forums.phpfreaks.com/topic/121824-preg-match/#findComment-628845 Share on other sites More sharing options...
JasonLewis Posted August 30, 2008 Share Posted August 30, 2008 Actually, that's not how you are supposed to use strpos, ProjectFear. You need to do something like: $str = "111:[email protected]:5080/111"; if(strpos("/", $str) !== FALSE){ echo "It's in there!"; }else{ echo "Couldn't find it!"; } That's because if the character appears at the first position in the string, strpos() returns 0, and not FALSE, but it's still evaluated as FALSE unless you explicitly say otherwise. Yeah if I took the time to look at the big red headings in the manual that say "WARNING". Thanks for the correction. Cheers. Link to comment https://forums.phpfreaks.com/topic/121824-preg-match/#findComment-629362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.