本文介绍了preg_replace问题 - ASCII字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要捕获一个网站的引荐来源并填充一个页面,其中包含指向

引用页面的链接。


如何使用preg_replace搜索并用

替换所有&符号(''&'')相应的HTML特殊字符('& amp;'')?


$ refurl = trim(getenv(" HTTP_REFERER"));

$ refhost = parse_url($ refurl);

$ refhost = preg_replace(" \& \\ \\," \& amp; \",$ refhost);


此代码返回警告并显示错误:


警告:输入中出现意外字符:''\''(ASCII = 92)状态= 1 in ...


解析错误:解析错误,意外'' ;''在...


提前致谢。

I need to capture referrers to a website and populate a page with links to the
referring pages.

How do I use preg_replace to search for and replace all ampersands (''&'') with
the corresponding HTML special character (''&'')?

$refurl = trim(getenv("HTTP_REFERER"));
$refhost = parse_url($refurl);
$refhost = preg_replace("\&\", "\&\", $refhost);

This code returns a warning and an error:

Warning: Unexpected character in input: ''\'' (ASCII=92) state=1 in ...

Parse error: parse error, unexpected '';'' in ...

Thanks in advance.

推荐答案




这篇关于preg_replace问题 - ASCII字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 18:35