I have an array of strings, and these strings have spaces in them. For example:
$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";
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);?> />
You need to quote the
valueattribute:Without doing that, the rendered HTML looks like:
Which the browser will handle as this: