vicodin Posted February 19, 2008 Share Posted February 19, 2008 Every time i run this function i get a Warning: preg_match() [function.preg-match]: No ending delimiter "|" No sure what im doing wrong. So what i want to accomplish is if there are any | in the string then take only the first peice of data and forget the rest. If there is no | in the string leave it alone. The script runs but i get a: Warning: preg_match() [function.preg-match]: No ending delimiter '|' found function Excludeit($str){ if(preg_match('|',$str)){ $str=substr($str,0,strpos($str,'|')); } else { $str=$str; } } Any ideas anyone.? Link to comment https://forums.phpfreaks.com/topic/91809-warning-preg_match-functionpreg-match-no-ending-delimiter/ Share on other sites More sharing options...
corbin Posted February 19, 2008 Share Posted February 19, 2008 preg_match takes regular expressions. Try looking into http://php.net/strpos . Or, if you want, you could do it with regular expressions, but it would be overkill. Link to comment https://forums.phpfreaks.com/topic/91809-warning-preg_match-functionpreg-match-no-ending-delimiter/#findComment-470209 Share on other sites More sharing options...
vicodin Posted February 19, 2008 Author Share Posted February 19, 2008 Im sorry i dont understand how just strpos is gonna help me in this situation. Link to comment https://forums.phpfreaks.com/topic/91809-warning-preg_match-functionpreg-match-no-ending-delimiter/#findComment-470214 Share on other sites More sharing options...
marcus Posted February 19, 2008 Share Posted February 19, 2008 <?php function Excludeit($str) { $ex = explode("|", $str); if(count($ex) > 1){ return $ex[0]; }else { return $str; } } echo Excludeit('pie|goat') . "<br>" . Excludeit('lemons'); ?> results pie lemons Link to comment https://forums.phpfreaks.com/topic/91809-warning-preg_match-functionpreg-match-no-ending-delimiter/#findComment-470219 Share on other sites More sharing options...
vicodin Posted February 19, 2008 Author Share Posted February 19, 2008 Dude your awesome! Thanks!!!! Link to comment https://forums.phpfreaks.com/topic/91809-warning-preg_match-functionpreg-match-no-ending-delimiter/#findComment-470227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.