[Master, please visit] PHP [global reference transfer] and [static variable] do not work two separate PHP files: PhpGlobal. php & nbsp; and & nbsp; PhpStatic. phpPhpGlobal. php content: & lt ;? Php/* $ FileName & nbsp;: & nbsp; P [master, please visit] PHP [global reference transfer] and [static variable] do not work
Two separate PHP files:
PhpGlobal. phpAnd
PhpStatic. php
All PhpGlobal. php content:
/*
$ 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 ("/Japan/I", $ string ))
{
$ CensorCount-> banned ++;
}
If (preg_match ("/Korea/I", $ string ))
{
$ CensorCount-> mod ++;
}
If (preg_match ("/Nima/I", $ string ))
{
$ CensorCount-> filter ++;
$ String = str_replace ("nima", "nima", $ string );
}
Return $ string;
}
$ Arr = array (
'Title' => "is Nima Korea better than Japan? ",
'Content' => "is Korea better than Japan? WHOSAIDSO? WHO! WHO! ",
'Author' => "Korea ratio ",
);
$ CensorCount = '';
Foreach ($ arr as $ k => $ v)
{
$ Arr [$ k] = censorCount ($ v );
}
Print_r ($ arr );
Echo'
';
Print_r ($ censorCount );
All PhpStatic. php content:
/*
$ FileName: PhpStatic. php
$ Output
>>>
Array
(
[Title] => ** nima ** is Korea better than Japan?
[Content] => is Korea better than Japan? WHOSAIDSO? WHO! WHO!
[Author] => Korea
)
0
*/
Function censorCount (& $ string)
{
Static $ censorCount;
Static $ cc = 0;
$ CensorCount = (object) array ('banned' => 0, 'mod' => 0, 'filter' => 0 );
If (preg_match ("/Japan/I", $ string ))
{
$ Cc ++;
$ CensorCount-> banned ++;
}
If (preg_match ("/Korea/I", $ string ))
{
$ Cc ++;
$ CensorCount-> mod ++;
}
If (preg_match ("/Nima/I", $ string ))
{
$ Cc ++;
$ CensorCount-> filter ++;
$ String = str_replace ("nima", "** nima **", $ string );
}
Return $ string;
}
$ Cc = 0;
$ Arr = array (
'Title' => "is Nima Korea better than Japan? ",
'Content' => "is Korea better than Japan? WHOSAIDSO? WHO! WHO! ",
'Author' => "Korea ratio ",
);
$ CensorCount = '';
Foreach ($ arr as $ k => $ v)
{
$ Arr [$ k] = censorCount ($ v );
}
Print_r ($ arr );
Echo'
';
Echo"$ Cc";
Print_r ($ censorCount );