[Coming soon] PHP [global reference transfer] and [static variable] do not work

Source: Internet
Author: User
[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 );


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.