我们有一个新闻站点,我正在尝试设置一个 str_replace
来将 &
从数据库中提取的位置转换为标准友好的 &
(用户仍然看到 &
)
发生的是我在可见站点上输出了以下示例:
Changing World". The report
Copper & Gold
而不是预期的空格或符号。数据是从带有文本字段的 mysqldb 中提取的。我哪里错了?
我的代码是:
function textfix($text){
$find = array('&', '<br>');
$replace = array('&', '<br />');
$newtext = str_replace($find, $replace, $text);
return $newtext;
}
html 的内容是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
最佳答案
这与
无关,但是如果你的 $text
中有
它将被更改为
还请告诉我们您在该 html 片段的源代码中看到了什么
关于php - 使用 str_replace 转换符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6692718/