可能重复:
quick function to replace ' with \' in php
Is there a PHP function that only adds slashes to double quotes NOT single quotes
我有例如:
$one = 'put "returns" between "paragraphs"';
$two = '"linebreak" add 2 spaces "at end"';
如何将其转换为:
$one = 'put \"returns\" between \"paragraphs\"';
$two = '\"linebreak\" add 2 spaces \"at end\"';
答案 0 :(得分:5)
要添加斜杠,请使用
$one = addslashes($one);
或删除
$one = stripslashes($one);
答案 1 :(得分:5)
$one = str_replace('"', '\"', $one);
答案 2 :(得分:4)
您正在寻找的功能是str_replace
或addcslashes
:
$one = 'put "returns" between "paragraphs"';
$slashed = addcslashes($one, '"');
echo $slashed;