【发布时间】:2012-12-09 06:47:31
【问题描述】:
为什么 preg_replace 在这种情况下不返回任何东西?我整晚都在想办法。
这是 $postContent 中包含的文本:
测试一下。这是一个报价:[Quote]1[/Quote] 报价现已结束。
这是我的代码:
echo "Test I'm Here!!!";
$startQuotePos = strpos($postContent,'[Quote]')+7;
$endQuotePos = strpos($postContent,'[/Quote]');
$postStrLength = strlen($postContent);
$quotePostID = substr($postContent,$startQuotePos,($endQuotePos-$postStrLength));
$quotePattern = '[Quote]'.$quotePostID.'[/Quote]';
$newPCAQ = preg_replace($quotePattern,$quotePostID,$postContent);
echo "<br />$startQuotePos<br />$endQuotePos<br />$quotePostID<br />Qpattern:$quotePattern<br />PCAQ: $newPCAQ<br />";
这是我的结果:
测试我在这里!!!
35
36
1
Qpattern:[Quote]1[/Quote]
PCAQ:
【问题讨论】:
标签: php preg-replace