日期:2014-05-17 浏览次数:20590 次
<?php
/*
$FileName : PhpGlobal.php
$Output:
>>>
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in D:\WebSite\MyHost\www.35dalu.com\public_html\test\PhpGlobal.PHP on line 10
*/
function censorCount(&$string)
{
global &$censorCount;
$censorCount = (object)array('banned' => 0,'mod'=> 0,'filter' => 0);
if(preg_match("/日本/i",$string))
{
$censorCount->banned++;
}
if(preg_match("/韩国/i",$string))
{
$censorCount->mod++;
}
if(preg_match("/尼玛/i",$string))
{
$censorCount->filter++;
$string = str_replace("尼玛","nima",$string);
}
return $string;
}
$arr = array(
'title' => "尼玛韩国比日本牛鼻吗?",
'content' => "韩国比日本牛鼻吗?WHOSAIDSO?WHO !WHO!",
'author' => "韩国比",
);
$censorCount = '';
foreach( $arr as $k => $v)
{
$arr[$k] = censorCount( $v );
}
print_r( $arr );
echo '<hr />';
print_r( $censorCount );
<?php
/*
$FileName : PhpStatic.php
$output
>>>
Array
(
[title] => **nima**韩国比日本牛鼻吗?
[content] => 韩国比日本牛鼻吗?WHOSAIDSO?WHO !WHO!
[author] => 韩国比
)
<hr /><b>0</b>
*/
function censorCount(&$string)
{
static $censorCount;
static $cc = 0;
$censorCount = (object)array('banned' => 0,'mod'=> 0,'filter' => 0);
if(preg_match("/日本/i",$string))
{
$cc++;
$censorCount->banned++;
}
if(preg_match("/韩国/i",$string))
{
$cc++;
$censorCount->mod++;
}
if(preg_match("/尼玛/i",$string))
{
$cc++;
$censorCount->filter++;
$string = str_replace("尼玛","**nima**",$string);
}
return $string;
}
$cc=0;
$arr = array(
'title' => "尼玛韩国比日本牛鼻吗?",
'content' => "韩国比日本牛鼻吗?WHOSAIDSO?WHO !WHO!",
'author' => "韩国比",
);
$censorCount = '';
foreach( $arr as $k => $v)
{
$arr[$k] = censorCount( $v );
}
print_r( $arr );
echo '<hr />';