$input = array(
'@\[(?i)br\](.*?)@si',
'@\[(?i)b\](.*?)\[/(?i)b\]@si',
'@\[(?i)i\](.*?)\[/(?i)i\]@si',
'@\[(?i)u\](.*?)\[/(?i)u\]@si',
'@\[(?i)img\](.*?)\[/(?i)img\]@si',
'@\[(?i)code\](.*?)\[/(?i)code\]@si',
'@\[(?i)s\](.*?)\[/(?i)s\]@si',
'@\[(?i)webs=(.*?)\](.*?)\[/(?i)webs\]@si',
'~\[(?i)color=(.*?)\](.*?)\[/(?i)color\]~s',
'@\[(?i)h1\](.*?)\[/(?i)h1\]@si',
'@\[(?i)h2\](.*?)\[/(?i)h2\]@si',
'@\[(?i)h3\](.*?)\[/(?i)h3\]@si',
'@\[(?i)h4\](.*?)\[/(?i)h4\]@si',
'@\[(?i)h5\](.*?)\[/(?i)h5\]@si',
'@\[(?i)h6\](.*?)\[/(?i)h6\]@si',
'@\[(?i)ul\](.*?)\[/(?i)ul\]@si',
'@\[(?i)ol\](.*?)\[/(?i)ol\]@si',
'@\[(?i)quote\](.*?)\[/(?i)quote\]@si',
'@\[(?i)a\](.*?)\[/(?i)a\]@si',
'~\[(?i)bcolor=(.*?)\](.*?)\[/bcolor\]~s',
'~\[(?i)t=(.*?):c=(.*?):p=(.*?):w=(.*?):s=(.*?)\](.*?)\[/t\]~s',
'@\[(?i)tr\](.*?)\[/(?i)tr\]@si',
'@\[(?i)td\](.*?)\[/(?i)td\]@si',
'~\[(?i)span=(.*?):c=(.*?)\](.*?)\[/span\]~s',
'~\[(?i)pre\](.*?)\[/pre\]~s'
);
$output = array(
'<br/>',
'<b>\\1</b>',
'<i>\\1</i>',
'<u>\\1</u>',
'<img src="\\1">',
'<code>\\1</code>',
'<s>\\1</s>',
'<a href="\\1">\\2</a>',
'<span style="color:$1;">$2</span>',
'<h1>\\1</h1>',
'<h2>\\1</h2>',
'<h3>\\1<h3>',
'<h4>\\1</h4>',
'<h5>\\1</h5>',
'<h6>\\1</h6>',
'<ul>\\1</ul>',
'<ol>\\1</ol>',
'<quote>\\1</quote>',
'<a>\\1</a>',
'<span style="background-color:\\1;">\\2</span>',
'<table border="\\1"cellspacing="\\2"cellpadding="\\3"width="\\4"style="background-color:\\5;">\\6</table>',
'<tr>\\1</tr>',
'<td>\\1</td>',
'<span style="background-color:\\1;color:\\2;">\\3</span>',
'<pre>\\1</pre>'
);
$post="[b]i love stackoverflow[/b]";
echo preg_replace($input,$output,$post);
之前代码工作正常,但我的代码现在返回一个空字符串。我读过preg_replace
已被弃用,但如何在代码中使用preg_replace_callback
?感谢。