Please advise how to remove white spaces before and after a sentence only. Example: " This is a sentence. " should be "This is a sentence."


Recommended Answers

All 3 Replies

Thank you for the link. The following code is working:

$str1 = "   This is a sentence.  ";
$str2 = ltrim(rtrim($str1," ")," ");
$str2 = trim($str1); // does the same
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.