【问题标题】:Using preg_replace to change <title> tag in php使用 preg_replace 更改 php 中的 <title> 标签
【发布时间】:2012-03-09 10:15:02
【问题描述】:

所以我将提供此代码,例如:

$str='<title>Test title here</title><meta name="description" content="test meta content here">';
$jftitle="here title 1";
$jfmeta ="here meta 2";

我有:

$str=preg_replace(array('/<title>(.*)<\/title>/i','/<meta name="description" content="(.*)">/i'),array('<title>'.$jftitle.'</title>','<meta name="description" content="'.$jfmeta.'">'),$str);

如果我对 $str 进行回显,它会返回“”。 谁能指出我正确的方向?

【问题讨论】:

    标签: php html regex preg-replace


    【解决方案1】:

    使用echo htmlspecialchars($str);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-31
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多