2012-03-09 126 views
0

所以我将例如提供这样的代码:使用preg_replace函数来改变在PHP <title>标签

$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); 

如果我做了$海峡的回声,它返回“”。 任何人都可以指向正确的方向吗?

+0

适合我。 – Toto 2012-03-09 10:36:32

+0

也适合我。 – piotrekkr 2012-03-09 10:59:19

回答

1

使用echo htmlspecialchars($str);