Home  >  Article  >  Backend Development  >  The Thirteenth Day of PHP Practice_PHP Tutorial

The Thirteenth Day of PHP Practice_PHP Tutorial

WBOY
WBOYOriginal
2016-07-14 10:11:14834browse

Today I revisited object-oriented programming and learned about __construct, a magic method that instantiates object parameters, and __destruct, a magic method that is executed before an object is destroyed
Also
The first parameter of __get to obtain the private member attribute is the obtained name
The first parameter of __set to set the private member attribute is the member name and the second parameter is the passed value
If __call does not find the matching method, it will be called. The first parameter is the name of the call, and the second parameter is the passed parameter
__isset is used to determine whether the member exists. The first parameter is the member name
__unset will be called when used to destroy members
[php]
/*
* Function strmin For example: if you want to get the full text as "12345", now you need to get "3", the front of <3> is "2", the end of <3> is "4",
* Parameter $nString text type, , for example: if you want to get the full text, it is 12345
* Parameter $sString text type, , the front of 3 is "2",
* Parameter $eString text type, , followed by 3 is "4"
* Parameter $position is an integer type, can be empty, the starting search position of the text to be found
* Parameter $isStr, logical type, nullable, default is false, case sensitive
*/
function strmin($nString,$sString,$eString,$position=0,$isStr)
{
If ($isStr) {
                $s=strpos($nString, $sString,$position);


                $e=strpos($nString, $eString,$s);
         }else{
                $s=stripos($nString, $sString,$position);


                $e=strpos($nString, $eString,$s);
         } 
          $s=$s+strlen($sString);
$e=$e-$s;
         return substr($nString,$s,$e);


}


/*
* Function strleft Click the text you want to find from the left side of the text to start searching
* Parameter $nString text type, , the text being searched
* Parameter $string text type, , the text to be found
* Parameter $position is an integer type, can be null, the starting search position of the text to be found
* Parameter $isStr, logical type, nullable, default is false, case sensitive
* Parameter $goNum, integer type, can be null, number of skips, the default is 0, no skip
*/
Function strleft($nString,$string,$position=0,$isStr=false,$goNum=0)
{
         $p=$position;


do {
                                                                                $goNum--;
echo $p."
";


If ($isStr) {
                $p=strpos($nString, $string,$p);
         }else{
                $p=stripos($nString, $string,$p);
         } 
                                                                                  $p++;


          } while ($goNum>=0);


          $p--; 
         return substr($nString,0,$p);
}  

/*
* Function strmin For example: if you want to get the full text as "12345", now you need to get "3", the front of <3> is "2", the end of <3> is "4",
* Parameter $nString text type, , for example: if you want to get the full text, it is 12345
* Parameter $sString text type, , the front of 3 is "2",
* Parameter $eString text type, , followed by 3 is "4"
* Parameter $position is an integer type, can be null, the starting search position of the text to be found
* Parameter $isStr, logical type, nullable, default is false, case sensitive
*/
function strmin($nString,$sString,$eString,$position=0,$isStr)
{
if ($isStr) {
$s=strpos($nString, $sString,$position);


$e=strpos($nString, $eString,$s);
}else{
$s=stripos($nString, $sString,$position);


$e=strpos($nString, $eString,$s);
}
$s=$s+strlen($sString);
$e=$e-$s;
Return substr($nString,$s,$e);


}


/*
* Function strleft Click the text you want to find from the left side of the text to start searching
* Parameter $nString text type, , the text being searched
* Parameter $string text type, , the text to be found
* Parameter $position is an integer type, can be null, the starting search position of the text to be found
* Parameter $isStr, logical type, nullable, default is false, case sensitive
* Parameter $goNum, integer type, can be null, number of skips, the default is 0, no skip
*/
function strleft($nString,$string,$position=0,$isStr=false,$goNum=0)
{
$p=$position;


do {
 
$goNum--;
echo $p."
";


if ($isStr) {
$p=strpos($nString, $string,$p);
}else{
$p=stripos($nString, $string,$p);
}
                         
$p++;


} while ($goNum>=0);


$p--;
Return substr($nString,0,$p);
}


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477371.htmlTechArticleToday I revisited object-oriented programming and learned about __construct, a magic method for instantiating object parameters, and __destruct. The magic methods executed before the object is destroyed include __get to obtain the private...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn