PHP转义字符
我使用的是PHP环境,在以转义字符的形式显示数据时遇到问题 例如: 如果我的字符串数据是PHP转义字符,php,stringescapeutils,Php,Stringescapeutils,我使用的是PHP环境,在以转义字符的形式显示数据时遇到问题 例如: 如果我的字符串数据是\” 与之相同,如果我的字符串数据是\要删除用作转义字符的\字符,请使用条斜杠功能 david@raston ~ $ cat tmp/test.php <?php $raw = 'double slash \\\\ escaped quote \"'; print $raw; print "\n"; print stripslashes($raw); ?> david@raston ~ $ p
\”
与之相同,如果我的字符串数据是
\
要删除用作转义字符的\
字符,请使用条斜杠
功能
david@raston ~ $ cat tmp/test.php
<?php
$raw = 'double slash \\\\ escaped quote \"';
print $raw;
print "\n";
print stripslashes($raw);
?>
david@raston ~ $ php tmp/test.php
double slash \\ escaped quote \"
double slash \ escaped quote "
david@raston~$cat tmp/test.php
david@raston~$php tmp/test.php
双斜杠\\转义引号\“
双斜杠\转义引号“
其他人都已经讨论过了,为了完整起见,我还建议大家看看herdoc
符号,当数据在多个上下文中发生变化时(例如PHP->HTML/JS->JS Regex),该符号非常有用
在表单上显示数据时,您需要HTML转义,而不是PHPIm不在HTML上显示数据,我提出这个问题是为了导出到excel。
<?php
echo <<<__EOF
It's not great for PHP indentation but often helps readability \ " ' `
__EOF;