【好手请近】PHP 【global引用传递】 和 【static 静态变量】 不起作用
程序员文章站
2022-06-15 13:17:00
...
【高手请近】PHP 【global引用传递】 和 【static 静态变量】 不起作用
两个单独的PHP文件:PhpGlobal.php 和 PhpStatic.php
PhpGlobal.php全部内容:
PhpStatic.php全部内容:
两个单独的PHP文件:PhpGlobal.php 和 PhpStatic.php
PhpGlobal.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 '
';
print_r( $censorCount );
PhpStatic.php全部内容:
/*
$FileName : PhpStatic.php
$output
>>>
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 );相关文章
相关视频