【高手请近】php 【global引用传递】 和 【static 静态变量】 不起作用
两个单独的php文件:phpglobal.php 和 phpstatic.php
phpglobal.php全部内容:
>>
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 '';
print_r( $censorcount );
phpstatic.php全部内容:
>>
array
(
[title] => **nima**韩国比日本牛鼻吗?
[content] => 韩国比日本牛鼻吗?whosaidso?who !who!
[author] => 韩国比
)
0
*/
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 '';
echo $cc;
print_r( $censorcount );