jay.barnes Posted August 14, 2009 Share Posted August 14, 2009 $cityandstate = "New York, NY"; if (preg_match(",",$cityandstate)) { echo "true"; } returns "Warning: preg_match() [function.preg-match]: No ending delimiter ',' found in test.php on line 37" what am I doing wrong, here??? Quote Link to comment https://forums.phpfreaks.com/topic/170276-probably-a-quick-question/ Share on other sites More sharing options...
Daniel0 Posted August 14, 2009 Share Posted August 14, 2009 You need a delimiter, i.e. a pair of characters that delimit the pattern. It could for instance be # in which case it would look like: preg_match('#,#', $cityandstate) The function strpos is better suited for this task though. Quote Link to comment https://forums.phpfreaks.com/topic/170276-probably-a-quick-question/#findComment-898220 Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 I would just use strpos() or stristr() to check if there is a comma in that string, as they are faster. $cityandstate = "New York, NY"; if (str_pos($cityandstate, ",") === true) { echo "true"; } Quote Link to comment https://forums.phpfreaks.com/topic/170276-probably-a-quick-question/#findComment-898221 Share on other sites More sharing options...
JonnoTheDev Posted August 14, 2009 Share Posted August 14, 2009 I would just use strpos() or stristr() to check if there is a comma in that string, as they are faster. $cityandstate = "New York, NY"; if (str_pos($cityandstate, ",") === true) { echo "true"; } $cityandstate = "New York, NY"; if(strpos($cityandstate, ",")) { echo "true"; } Quote Link to comment https://forums.phpfreaks.com/topic/170276-probably-a-quick-question/#findComment-898238 Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 oops, didn't think it had an underscore, but thought I saw it somewhere. yeah sorry for incorrect code Quote Link to comment https://forums.phpfreaks.com/topic/170276-probably-a-quick-question/#findComment-898239 Share on other sites More sharing options...
jay.barnes Posted August 14, 2009 Author Share Posted August 14, 2009 AAhhh...I understand now...I thought ($cityandstate, ",") was setting the comma as the delimiter - I read the manual page wrong. I"m basically trying to find out if a string contains a comma, and, if it does, execute some commands I'll look at strpos(), and see if that better suits my needs. Thanks for your help, guys! Quote Link to comment https://forums.phpfreaks.com/topic/170276-probably-a-quick-question/#findComment-898248 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.