Use PHP to implement PHP script engine built-in functions again

Source: Internet
Author: User

// It's really boring. It's a strange idea. I want to re-use PHP to implement some encapsulated functions in PHP,
// The following code mainly implements some string processing functions in PHP, and implements some PHP
// None, but the same function of string processing functions can also be implemented in other languages.
// Now, such as using C/VBScript/Perl, you can have your own function library.
// The following functions may not be able to run successfully, just for learning.
//
// If there is no special statement, it is all because heiyeluren is original. Please keep the author information if you want to use any function.


// {Strlen ()
/**
* Count string length
*
* @ Param string $ str need count length string variable
* @ Return int return count result
*/
Function strlen1 ($ str)
{
If ($ str = '')
Return 0;

$ Count = 0;
While (1)
{
If ($ str [$ count]! = NULL)
{
$ Count;
Continue;
}
Else
Break;
}
Return $ count;
}
//}}}


// {Substr ()
/**
* Get sub string
*
* @ Param string $ str need get sub string variable
* @ Param int $ start get sub string
* @ Param int $ length need get string length
* @ Return string return sub string
*/
Function substr1 ($ str, $ start, $ length = 0)
{
If ($ str = '')
Return;
If ($ start> strlen ($ str ))
Return;
If ($ length! = NULL) & ($ start> 0) & ($ length> strlen ($ str)-$ start ))
Return;
If ($ length! = NULL) & ($ start <0) & ($ length> strlen ($ str) $ start ))
Return;

If ($ length = NULL)
$ Length = (strlen ($ str)-$ start );

If ($ start <0)
{
For ($ I = (strlen ($ str) $ start); $ I <(strlen ($ str) $ start $ length); $ I)
{
$ Substr. = $ str [$ I];
}
}

If ($ length> 0)
{
For ($ I = $ start; $ I <($ start $ length); $ I)
{
$ Substr. = $ str [$ I];
}
}

If ($ length <0)
{
For ($ I = $ start; $ I <(strlen ($ str) $ length); $ I)

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.