转换PHP变量中的特殊字符


Convert special characters from PHP variables?

我可以打印带有以下内容的url:

<?php print $base_url . $node_url ?>

转换特殊字符的标准PHP方法是什么?

因此,与其:http://time.com/3525666/ebola-psychology-fear-symptoms/

我需要http%3A%2F%2Time.com%2F33525666%2埃博拉心理恐惧症状%2F

您可以使用urlencode进行这种转义。

存在其他用于其他目的的转义函数,如htmlspecialchars,用于安全地输出用于HTML显示的文本。

在php中使用his函数,它是内置在函数中以url格式编码的

  urlencode(); 

只需添加一点,如上所述,htmlspecialchar可以处理少数html实体,而不是全部。

改为使用htmlenties():

$query_string='foo='.urlencode($foo).'&bar='。urlencode($bar);echo";