<?php
$str = "Hello Experts PHP
Top Website Experts php ";
$cleanStr = trim(preg_replace('/\s\s+/', ' ', str_replace("\n", " ", $str)));
echo $cleanStr;
?>
Remove Multiple Extra Whitespace and Convert into Single Space Using PHP?
Friends experts php will tell you today how you can convert multiple extra space between words of any string into single space.
How to Replace multiple whitespace characters with a single space, How to Remove White Space from a String in PHP
You are explained by example below.
Input String Question :- $str = "Hello Experts PHP
Top Website Experts php ";
Output String Question :- $str = "Hello Experts PHP Top Website Experts php";
34
Views