I want to explode ' ' in a string but php add it again.
here's my code:
$str = "MyText1
MyText2
MyText3";
//convert to array
$arr = explode("
", $str); //Why PHP adding '
' again here??
//prepare the var
$new_str = "";
//combine to string again
foreach( $arr as $value ) {
$new_str .= "prefix-" . $value . "-suffix ";
}
echo $new_str;
the result is:
prefix-MyText1
-suffix prefix-MyText2
-suffix prefix-MyText3-suffix
I want the result to be:
prefix-MyText1-suffix prefix-MyText2-suffix prefix-MyText3-suffix
I found the problem. it works on linux, it wont work on windows. linux uses " ", windows uses " "