从PHP变量转换特殊字符?

时间:2014-10-22 19:33:08

标签: php

我可以使用以下内容打印网址:

<?php print $base_url . $node_url ?>

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

所以代替:http://time.com/3525666/ebola-psychology-fear-symptoms/

我需要http%3A%2F%2Ftime.com%2F3525666%2 Febola-psychology-fear-symptoms%2F

3 个答案:

答案 0 :(得分:1)

您可以使用urlencode进行此类转义。

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

答案 1 :(得分:1)

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

  urlencode(); 

答案 2 :(得分:0)

只是添加,htmlspecialchars,如上面在评论中提到的可以处理几个html实体,而不是所有的。

改为使用htmlentities():

$ QUERY_STRING = '富=' .urlencode($富)。 '&安培;栏='。进行urlencode($巴);回声 '';

相关问题