编码问题,覆盖& amp;到&对于html使用php [英] Encoding issue, coverting & to & for html using php

查看:223
本文介绍了编码问题,覆盖& amp;到&对于html使用php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html中有一个网址:

I have a url in html:

<a href="index.php?q=event&amp;id=56&amp;date=128">

我需要将其转换为一个字符串:

I need to turn it into a string exactly as:

<a href="index.php?q=event&id=56&date=128">

我知道如何使用preg_replace等,但是在php中有一个函数直接编码,我可以用于其他编码问题,如& nsbp(或任何它是,等)?理想情况下,我会发送我的字符串到函数,它会输出'&'而不是& amp。有转换&TEXT的通用功能;成为一个真正的角色?

I know how to do this with preg_replace etc, but is there a function in php that deals directly with encoding that I can use for other encoding issues such as &nsbp (or whatever it is, etc)? Ideally I would send my string into the function and it would output '&' instead of &amp. Is there a universal function for converting &TEXT; into an actual character?

编辑:对不起,在我完成输入问题之前发布。 QUESTION现已完成。

sorry, posted this before I finished typing the question. QUESTION is now complete.

推荐答案

使用 html_entity_decode()

$newUrl = html_entity_decode('<a href="index.php?q=event&amp;id=56&amp;date=128">');
echo $newUrl; // prints <a href="index.php?q=event&id=56&date=128">

这篇关于编码问题,覆盖&amp; amp;到&amp;对于html使用php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆