php implode breaks on spaces
$arr = array('bob', 'john smith', 'grease monkey', 'etc');
Why is it when I try to $str = implode('|', $arr);
, it stops at the first space it finds??
I'm left with a string like:
$str = "bob|john";开发者_如何学JAVA
If I try:
$arr = array('bob', 'john', 'grease monkey', 'etc');
and implode, I get:
$str = "bob|john|grease";
Edit: I'm actually trying to set it to the value of a hidden field:
<input id="hidLblFields" name="hidLblFields" type="text" value=<?php echo implode('|', $myFields);?> />
Edit: I'm actually trying to set it to the value of a hidden field:
<input id="hidLblFields" name="hidLblFields" type="text" value=<?php echo implode('|', $myFields);?> />
You need to quote the value
attribute:
<input .. type="text" value="<?php echo implode('|', $myFields);?>" />
Without doing that, the rendered HTML looks like:
<input type="text" value=bob|john|grease monkey />
Which the browser will handle as this:
<input type="text" value="bob|john|grease" monkey />
You must have an error somewhere else in your code, implode() does not break on spaces.
$arr = array('bob', 'john', 'grease monkey', 'etc');
$str = implode('|', $arr);
var_dump($str);
// gives
string(26) "bob|john|grease monkey|etc"
As for your edit, you need quotes around attributes in html:
<input id="hidLblFields" name="hidLblFields" type="text" value="<?php echo implode('|', $myFields);?>" />
This is simply not possible. You have some other functions doing some other operations
Worked for me. Try not reassigning your variables:
<?php
$str = array('bob', 'john smith', 'grease monkey', 'etc');
$new_str = implode('|', $str);
echo $new_str;
?>
精彩评论