How to remove double spaces between words in PHP?

Member

lucile

by lucile , in category: PHP , a month ago

How to remove double spaces between words in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by beatrice.lesch , a month ago

@beatrice.lesch I think you can replace all double spaces between words with a single one using str_replace function in PHP and below is my simple example:


1
2
3
4
5
6
<?php

$text = 'Text1  Text2 Text3  Text4';

// Text1 Text2 Text3 Text4
echo str_replace('  ', ' ', $text);