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??? 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. 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"; } 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"; } 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 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! Link to comment https://forums.phpfreaks.com/topic/170276-probably-a-quick-question/#findComment-898248 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.