Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP转义字符_Php_Javascript - Fatal编程技术网

PHP转义字符

PHP转义字符,php,javascript,Php,Javascript,我已经阅读了类似的线程,但我不知道如何转义以下字符串中的字符: $var = '<a href="'.$confUrl.'/index.php?a=profile&u='.$TMPL['username'].'&r=2"></a>'; 你没有用引号括住你的URL。应该是: $var = '<a onclick="window.location.assign(\''.$confUrl.'/index.php?a=profile

我已经阅读了类似的线程,但我不知道如何转义以下字符串中的字符:

$var =  '<a href="'.$confUrl.'/index.php?a=profile&u='.$TMPL['username'].'&r=2"></a>';

你没有用引号括住你的URL。应该是:

$var =  '<a onclick="window.location.assign(\''.$confUrl.'/index.php?a=profile&u='. urlencode($TMPL['username']) . '&r=2\'')"></a>';
建议使用“
$var=”以避免URL中出现不需要的字符

$var =  '<a onclick="window.location.assign(\''.$confUrl.'/index.php?a=profile&u='. urlencode($TMPL['username']) . '&r=2\'')"></a>';
<a onclick="window.location.assign('someURL/index.php?a=profile&u=someUsername&r=2')"></a>