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>