2011-09-22 23 views
0

不知道這是可能的,但在我的模板,我有這樣的代碼:PHP使用str_replace奇怪的模板字符串?

Title Here<!--firstTitle--> 

我想知道是否有使用str_replace函數輸出這樣的方式:

<h2>Title Here</h2> 

我可以做一邊,但不是其他?

在此先感謝!

回答

3

不,不是用str_replace函數 但是,如果標題是該行的開始,嘗試了preg_replace

preg_replace('~^(.*?)<!--firstTitle-->~', '<h2>$1</h2>', $string); 
+0

優秀!好東西!!感謝那!! – eberswine