This question already has an answer here:
How can i trim()
the following sentence
,, This is New, A new Sentence.,
to become
This is New, A new Sentence
I've tried trim()
and rtrim()
together and didn't work either,
$str = ",, This is New, A new Sentence., ";
$str = trim(rtrim($str));
result was always the same with or together trim
and rtrim()
,, This is New, A new Sentence.,
Is it possible to handle this using trim()
function?
In case the solution is using preg_replace()
, Then the current RegEx
i use is preg_replace('/[\s,]+/',',',trim(rtrim($str)))
</div>