This tutorial provides a few PHP tutorials to remove a space in a string a variety of methods Oh, using the PHP function, Str_replace,trim, regular and so on to replace the space of the string effective method
A function with PHP itself
Str_replace ("", "", $str);
To replace
<?php
$str = "# #使用函数trim去掉字符串两端特定字符";
$str 1 = Trim ($str, "#"); Pass in the second argument for the function trim, trim will remove the string $str the # character at both ends
echo $str. " <br> ";
echo $str 1;
?>
Instance
<?php
$STR = "Use function trim to remove whitespace characters from both ends of the string";
$str 1 = Trim ($STR); echo "Before processing has". strlen ($STR). Characters ";
echo "<br/>";
echo "<br/>";
echo "processed with the Trim function". strlen ($str 1). Characters ";
?>
Look at a higher level.
PHP program Deletes "space" in "string element" in "array"
?
$arr =array ();
$arr []= "ad DFD DFD";
$arr []= "SAF SDF DSF";
$arr []= "SDF DSFGFD DD";
$arr []= "DFD dfferw";
while (list ($name, $value) =each ($arr)) {
Echo $value;
$arr 2[]=trim ($value);//Go to space
}
Print_r ($arr 2);//This should be the array you want.
?>
Try to remove a space with a regular expression
$string = Preg_replace ("/s+ ([rn$])/", "1", $string);
When ' $ ' is inside [], www.45it.net does not represent the ' end of string
---------------------------------------------------------------
$string = Preg_replace ("/s+ ([x20]|$)/", "1", $string);
---------------------------------------------------------------
$string = Preg_replace ("/x20+ ([rn]|$)/", "1", $string);
---------------------------------------------------------------
$string = Preg_replace ('/([RN]) [s]+/', ' 1 ', $string);