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.? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
vicodin Posted February 19, 2008 Author Share Posted February 19, 2008 Dude your awesome! Thanks!!!! Quote Link to comment 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.