Php 向字符串问题添加字符
我将字符添加到一串单词中,但没有得到所需的结果 我有这样一个字符串:$string=word 我需要的输出是:'word'+'word'+'word'+'word' 我得到的是:单词+单词+单词+单词+ 以下是我正在使用的函数:Php 向字符串问题添加字符,php,string,Php,String,我将字符添加到一串单词中,但没有得到所需的结果 我有这样一个字符串:$string=word 我需要的输出是:'word'+'word'+'word'+'word' 我得到的是:单词+单词+单词+单词+ 以下是我正在使用的函数: $str = "word word word word"; $str = implode("+", explode(" ", $str))."+"; echo $str; 内爆并连接周围的撇号,如下所示: $str = "word word word word";
$str = "word word word word";
$str = implode("+", explode(" ", $str))."+";
echo $str;
内爆并连接周围的撇号,如下所示:
$str = "word word word word";
$str = "'" . implode("'+'", explode(" ", $str)) . "'";
echo $str;
$str = "'".str_replace(' ', "'+'", $str)."'";
内爆并连接周围的撇号,如下所示:
$str = "word word word word";
$str = "'" . implode("'+'", explode(" ", $str)) . "'";
echo $str;
$str = "'".str_replace(' ', "'+'", $str)."'";
只需在两侧连接单个QOUTE:
$str = "'".implode("'+'", explode(" ", $str))."'";
^^ ^ ^ ^
// outside quotes inside quotes outside qoutes
或者像这样:
$str = "word word word word";
$str = "'" . implode("'+'", explode(" ", $str)) . "'";
echo $str;
$str = "'".str_replace(' ', "'+'", $str)."'";
只需在两侧连接单个QOUTE:
$str = "'".implode("'+'", explode(" ", $str))."'";
^^ ^ ^ ^
// outside quotes inside quotes outside qoutes
或者像这样:
$str = "word word word word";
$str = "'" . implode("'+'", explode(" ", $str)) . "'";
echo $str;
$str = "'".str_replace(' ', "'+'", $str)."'";
你认为最后这一点在做什么??你认为最后这一点在做什么??这很有效。谢谢你进一步解释!我的测试非常有效,但当我在插入数据库之前将其作为表单post函数的一部分时,整个表单post将不会插入mysql数据库。@Jason我想知道这是什么上下文,您如何使用它。你应该早点把它贴出来,可能是因为引用没有在querry@Jason在查询中使用mysql\u real\u escape\u字符串之前,最后使用它,效果非常好。谢谢你进一步解释!我的测试非常有效,但当我在插入数据库之前将其作为表单post函数的一部分时,整个表单post将不会插入mysql数据库。@Jason我想知道这是什么上下文,您如何使用它。你应该早点把它贴出来,可能是因为引用没有在querry@Jason在查询中使用mysql\u real\u escape\u字符串之前,请先使用它