上原代码:
$sf_content = preg_replace_callback( "/(<script\s+.*?>.*?<\/script>)|(<a\s+.*?>.*?<\/a>)|(<img\s+.*?[\/]?>)|(\[attach\](\d+)\[\/attach\])/is", function($r) { return SF_inlink::base64_trans("encode", "<t_m_p>", (isset($r[1])?$r[1]:'').(isset($r[2])?$r[2]:'').(isset($r[3])?$r[3]:'').(isset($r[4])?$r[4]:''), "</t_m_p>"); }, $sf_content );
错误原因就是这个$r导致的~囧,在PHP5.2中 未定义变量 导致这个使用preg_replace_callback出现的【unexpected T_FUNCTION 】错误
修改后的代码:
public static function replacea($matches) { return SF_inlink::base64_trans("encode", "<t_m_p>", (isset($matches[1])?$matches[1]:'').(isset($matches[2])?$matches[2]:'').(isset($matches[3])?$matches[3]:'').(isset($matches[4])?$matches[4]:''), "</t_m_p>"); } public static function replaceb($matches) { return SF_inlink::base64_trans("decode", "", $matches[1], ""); } public static function keywordaction($sf_content,$sf_tagstyle,$tag,$sf_onemaxnum){ global $_G; $_G['SF_inlink_k_tmp'] = array(); $matches = array(); $sf_content = preg_replace_callback( "/(<script\s+.*?>.*?<\/script>)|(<a\s+.*?>.*?<\/a>)|(<img\s+.*?[\/]?>)|(\[attach\](\d+)\[\/attach\])/is", array('SF_inlink', 'replacea'), $sf_content ); if(isset($sf_tagstyle)){ $sf_content=preg_replace("/(".$tag->Name.")(?=[^<>]*<)/iU",'<a style="'.$sf_tagstyle.'" href="'.$tag->Url.'">${1}</a>',$sf_content,$sf_onemaxnum); }else{ $sf_content=preg_replace("/(".$tag->Name.")(?=[^<>]*<)/iU",'<a href="'.$tag->Url.'">${1}</a>',$sf_content,$sf_onemaxnum); } $sf_content = preg_replace_callback( "/<t_m_p>(.*?)<\/t_m_p>/is", array('SF_inlink', 'replaceb'), $sf_content ); return $sf_content; }
此错误在PHP官方解释中也有说明
If you want to call non-static function inside your class, you can do something like this。
For PHP 5.2 use second argument like array($this, 'replace')。
For PHP 5.3 use second argument like "self::replace"。