Friday, 22 March 2013

PHP Replace new lines, tabs and multiple spaces with single space


preg_replace('/\\s+/', ' ',$data) used to Replace new lines, tabs and multiple spaces with single space in PHP

example:
<?php
$data = 'Hi     tab i am 
new line    more                spaces';
$data= preg_replace('/\\s+/', ' ',$data);
echo $data;
?>

Output:

Hi tab i am new line more spaces

Share This!



No comments:

Post a Comment

Here We Write The Problems we face at different situations and Solutions to those problems.