我想改变任何''by a' - '
我这样做:
$tagname = $taginfo[1]; /* something like $tagname = 'A tag with spaces' */
$tagurl = urlencode($tagname);
$tagsize = 9 + intval($numtags)*2;
$bla = 'function("'.str_replace(' ','-',$tagname).'")';
$ bla将用于附加到onclick属性
任何想法为什么结果
onclick="function('A tag with spaces')"
而不是
onclick="function('A-tag-with-spaces')"
?可能htmlspecialchars必须用它做什么?
答案 0 :(得分:2)
urlencode($tagname);
会将您的空格变为%20
,因此您的字符串将为
A%20tag%20with%20spaces
您可以将%20
替换为-
,也可以在编码前执行替换。