我想要把扼杀(“[TOREPLACE]”)的首例出现在一个论坛的岗位上,但只有在这种扼杀不是用纸面法标的环绕的情况下。
我的法典:
if($firstpos = strpos($post[ pagetext ], [TOREPLACE] ) !== false){
//check for quote
if($quote_start = strpos($post[ pagetext ], [QUOTE ) !== false && $quote_end = strpos($post[ pagetext ], [/QUOTE] ) !== false){
//quote found
//check if quote starts before egg
if($quote_start < $firstpos && $firstpos < $quote_end){
//don t replace, because the string that is to be replace is in between quotes
}
}
$post[ pagetext_html ] = preg_replace( ~[TOREPLACE]~i , <img src="/src.jpg" border="0" /> , $post[ pagetext_html ], 1);
}
I would have to loop this to find the first occurence of the string that is not between quotes. This quote check is tedious and not very elegant. Does anybody know of a better algorithm to do the above?
Algorithm: If quotes in post——发现并替换在报价标之间不存在的第一种情况。 如无引言,取代第一种情况:>
Maybe I could add all this to the pre_match. The quotes are optional, though, and I don t know how to do it.