Hello Reader's! if you are dealing with excess whitespace on the beginning or end of the string then you can use trim(), ltrim() or rtrim() to remove them. Also If have to delete extra spaces within a string consider a preg_replace() of multiple whitespaces " "* with a single whitespace " ".
Let's see and example below:-
$str = trim(preg_replace('/\s+/',' ', $str));
Or you can also use:-
$productID=preg_replace('/[\s]+.*/','',$productID);
Now the new $str and $productID will have no more spaces left.
0 Comment(s)