我需要生成imacro语法,以便用户能够从浏览器屏幕上进行复制。
由于iMacro对空格使用<SP>
,所以我需要用<SP>
替换具有空格的数据库值。
这是不起作用的,因为浏览器将<SP>
识别为HTML字符。
$srtnew = str_replace(" ","<SP>",$string);
有什么建议吗?
发布于 2014-01-03 22:54:06
你得做:
header("Content-Type:text/plain");
在你输出之前。
这告诉浏览器以纯文本格式输出内容,而不是以html格式输出内容。
当然,你也可以这样做:
$srtnew = str_replace(" ",htmlentities("<SP>"),$string);
如果您有许多标记,如果您只想输出该代码以便让您的用户复制它们,那么就应该设置标头。
有关在PHP:http://www.php.net/manual/de/function.header.php中设置标头的更多信息
发布于 2014-01-03 22:58:38
您可以将HTML实体用于斜角括号(<
和>
):
$srtnew = str_replace(" ","<SP>",$string);
或者,您可以使用PHP的htmlentities()
对括号进行编码:
$srtnew = str_replace(" ",htmlentities("<SP>"),$string);
工作示例(PhpFiddle)
https://stackoverflow.com/questions/20914169
复制相似问题