Removing the space into string using php.this problem facing many time by the php coder. i am trying to solve this problem here.remove extra space from string using php,remove space in php,how to hide extra space from string using php.
Type 1 : trim( ) Function
This function only remove space before and after the string
<?php
$str=" This is only for test ";
echo trim($str);
?>
// output
This is only for test
Type 2 : preg_replace( ) Function
Type 1 : trim( ) Function
This function only remove space before and after the string
<?php
$str=" This is only for test ";
echo trim($str);
?>
// output
This is only for test
Type 2 : preg_replace( ) Function
This Function remove space between the string
<?php
$str="This is only for test";
$str = preg_replace("/\s+/"," ",$str);
echo $str;
?>
//output
This is only for test
if you like this please comment this
No comments:
Post a Comment