我正在将字符添加到字符串中,而没有完全得到我需要的结果。将字符添加到字符串问题
我有一个这样的字符串:$string = "word word word word"
我所需要的输出为:'word'+'word'+'word'+'word'
我所得到的是:字+字+字+字+
这里是我的功能使用:
$str = "word word word word";
$str = implode("+", explode(" ", $str))."+";
echo $str;
我正在将字符添加到字符串中,而没有完全得到我需要的结果。将字符添加到字符串问题
我有一个这样的字符串:$string = "word word word word"
我所需要的输出为:'word'+'word'+'word'+'word'
我所得到的是:字+字+字+字+
这里是我的功能使用:
$str = "word word word word";
$str = implode("+", explode(" ", $str))."+";
echo $str;
正好连接两侧单qoutes:
$str = "'".implode("'+'", explode(" ", $str))."'";
^^ ^^ ^
// outside quotes inside quotes outside qoutes
或者这样:
$str = "'".str_replace(' ', "'+'", $str)."'";
内爆并连接周边撇号这样的:
$str = "word word word word";
$str = "'" . implode("'+'", explode(" ", $str)) . "'";
echo $str;
你觉得这是什么位,结束时做' “+”;'?? – 2014-09-22 03:25:33