takn25 Posted March 12, 2011 Share Posted March 12, 2011 Hi, I want to check two things if some one could help thanks. I am not an expert at REGEX just learning. Firstly I want to check if a string has a - at the end for example. $string= "Lion"; There is no - at the end I would like to add a ( - ) . So $string becomes LION- Second thing I want to check for example if the user has inputted some excessive use of BLANK SPACE and turn it in to just single space for example. I ROCK THIS becomes I ROCK THIS. Thanks help is much appreciated. Link to comment https://forums.phpfreaks.com/topic/230404-checking-a-few-strings/ Share on other sites More sharing options...
.josh Posted March 12, 2011 Share Posted March 12, 2011 $string .= (substr($string,-1) == '-') ? '' : '-'; $string = preg_replace('~\s+~',' ',$string); Link to comment https://forums.phpfreaks.com/topic/230404-checking-a-few-strings/#findComment-1186597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.