【高手请近】PHP 【global引用传递】 和 【static 静态变量】 不起作用
两个单独的PHP文件:PhpGlobal.php 和 PhpStatic.php
PhpGlobal.php全部内容:
<br /> <?php<br /> /*<br /> $FileName : PhpGlobal.php<br /> $Output:<br /> >>><br /> Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in D:\WebSite\MyHost\www.35dalu.com\public_html\test\PhpGlobal.PHP on line 10<br /> */<br /> function censorCount(&$string)<br /> {<br /> global &$censorCount;<br /> $censorCount = (object)array('banned' => 0,'mod'=> 0,'filter' => 0);<br /> if(preg_match("/日本/i",$string))<br /> {<br /> $censorCount->banned++;<br /> }<br /> <br /> if(preg_match("/韩国/i",$string))<br /> {<br /> $censorCount->mod++;<br /> }<br /> <br /> if(preg_match("/尼玛/i",$string))<br /> {<br /> $censorCount->filter++;<br /> $string = str_replace("尼玛","nima",$string);<br /> }<br /> <br /> return $string;<br /> }<br /> <br /> $arr = array(<br /> 'title' => "尼玛韩国比日本牛鼻吗?",<br /> 'content' => "韩国比日本牛鼻吗?WHOSAIDSO?WHO !WHO!",<br /> 'author' => "韩国比",<br /> );<br /> <br /> $censorCount = '';<br /> <br /> foreach( $arr as $k => $v)<br /> {<br /> $arr[$k] = censorCount( $v );<br /> }<br /> <br /> print_r( $arr );<br /> echo '<hr />';<br /> print_r( $censorCount );<br /> <br />
<br> <?php <br /> /*<br> $FileName : PhpStatic.php<br> $output<br> >>><br> <br> Array<br> (<br> [title] => **nima**韩国比日本牛鼻吗?<br> [content] => 韩国比日本牛鼻吗?WHOSAIDSO?WHO !WHO!<br> [author] => 韩国比<br> )<br> <hr><b>0</b><br> <br> */<br> <br> function censorCount(&$string)<br> {<br> static $censorCount;<br> static $cc = 0;<br> $censorCount = (object)array('banned' => 0,'mod'=> 0,'filter' => 0);<br> if(preg_match("/日本/i",$string))<br> {<br> $cc++;<br> $censorCount->banned++;<br> }<br> <br> if(preg_match("/韩国/i",$string))<br> {<br> $cc++;<br> $censorCount->mod++;<br> }<br> <br> if(preg_match("/尼玛/i",$string))<br> {<br> $cc++;<br> $censorCount->filter++;<br> $string = str_replace("尼玛","**nima**",$string);<br> }<br> <br> return $string;<br> }<br> $cc=0;<br> <br> $arr = array(<br> 'title' => "尼玛韩国比日本牛鼻吗?",<br> 'content' => "韩国比日本牛鼻吗?WHOSAIDSO?WHO !WHO!",<br> 'author' => "韩国比",<br> );<br> <br> $censorCount = '';<br> <br> foreach( $arr as $k => $v)<br> {<br> $arr[$k] = censorCount( $v );<br> }<br> <br> print_r( $arr );<br> echo '<hr>';<br> echo "<b>$cc</b>";<br> print_r( $censorCount );<br> <br> <br> <div class="clear"> </div>