Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace   with a blank or empty string PHP

Well, I have tried these and it seems that none of them are working, my example string is

 $text_description="       Hello world! lorel ipsum";

 $text_description= str_replace(" "," ",$text_description);
 $text_description = preg_replace("/&#?[a-z0-9]+;/i"," ",$text_description);
 $text_description=html_entity_decode($text_description);
like image 299
Sandhurst Avatar asked Jun 09 '26 10:06

Sandhurst


1 Answers

$text_description="       Hello world! lorel ipsum";
$text_description = str_replace(' ', ' ', $text_description);
echo $text_description;

Output:

Hello world! lorel ipsum

like image 121
Michael Robinson Avatar answered Jun 10 '26 23:06

Michael Robinson