oldwizard Posted March 2, 2013 Share Posted March 2, 2013 Hi guys i keep geting this warning on my site: Warning: preg_match() [function.preg-match]: No ending delimiter '-' found in /home/content/96/10289996/html/libraries/Trash.php on line 501 and this is what is on line 501: if( preg_match( '-', $p ) ){ $aExp = explode( '-', $p ); can someone help me please. Carlos Quote Link to comment https://forums.phpfreaks.com/topic/275126-warning-preg_match-functionpreg-match-no-ending-delimiter-found-in/ Share on other sites More sharing options...
Jessica Posted March 2, 2013 Share Posted March 2, 2013 You should probably just use strpos. Make sure to check if its !== FALSE. Quote Link to comment https://forums.phpfreaks.com/topic/275126-warning-preg_match-functionpreg-match-no-ending-delimiter-found-in/#findComment-1416017 Share on other sites More sharing options...
AyKay47 Posted March 2, 2013 Share Posted March 2, 2013 To directly answer your question, patterns need to be wrapped in delimiters (e.g /$pattern/, ~$pattern~). But as Jessica said, strpos() will be a faster/more efficient solution for a character search in a string. Quote Link to comment https://forums.phpfreaks.com/topic/275126-warning-preg_match-functionpreg-match-no-ending-delimiter-found-in/#findComment-1416045 Share on other sites More sharing options...
oldwizard Posted March 2, 2013 Author Share Posted March 2, 2013 Well, if i say that is chinese to me would you believe it? I know very little about php coding, can you please give me an example on how to wright the code? Thanks for the quick response guys. Carlos Quote Link to comment https://forums.phpfreaks.com/topic/275126-warning-preg_match-functionpreg-match-no-ending-delimiter-found-in/#findComment-1416048 Share on other sites More sharing options...
AyKay47 Posted March 2, 2013 Share Posted March 2, 2013 if(strpos($p, "-") !== FALSE) { //execute true block } else { //handle error } Quote Link to comment https://forums.phpfreaks.com/topic/275126-warning-preg_match-functionpreg-match-no-ending-delimiter-found-in/#findComment-1416049 Share on other sites More sharing options...
Christian F. Posted March 3, 2013 Share Posted March 3, 2013 The PHP manual contains lots of examples for all of the functions, especially the core functions like strpos. That's why we tend to recommend people to check it, if they are uncertain about how to use a function in PHP. You'll find everything you need in it, not just examples, btw, but also definitions and user comments. Quote Link to comment https://forums.phpfreaks.com/topic/275126-warning-preg_match-functionpreg-match-no-ending-delimiter-found-in/#findComment-1416106 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.