About phptuts

Author Archive | phptuts
PHP: Convert IP Range to CIDR

PHP: Convert IP Range to CIDR

Read first: PHP: Convert CIDR to ipaddress range PHP: check valid ipaddress or CIDR notation range This function work done with small IP range ex: 111.234.23.1 – 11.234.23.243 Solution 1 Example of usage: result: Array ( [0] => 121.0.47.0/32 [1] => 121.0.47.1/31 [2] => 121.0.47.3/30 [3] => 121.0.47.7/29 [4] => 121.0.47.15/28 [5] => 121.0.47.31/26 [6] […]

Read full story Comments { 1 }
PHP: check valid ipaddress or CIDR notation range

PHP: check valid ipaddress or CIDR notation range

This function checks for a valid IP address or CIDR notation address range. Example of usage:

Read full story Comments { 0 }
PHP: Convert CIDR to ipaddress range

PHP: Convert CIDR to ipaddress range

This function takes an IP address and CIDR netmask (e.g. 102.68.1.0/25), and calculate IP address range in that netblock. Example: result: array(2) { [0]=> string(10) “102.68.1.0” [1]=> string(12) “102.68.1.127” }

Read full story Comments { 0 }
PHP: Crop image function (part 2)

PHP: Crop image function (part 2)

Read first: PHP: Crop image function We can save to new file: Online demo We get the result: http://www.demo.tutorialspots.com/crop/logo.png Now, we can crop image on the fly: Source code of file crop.php Example 1: PHP logo Source picture http://www.demo.tutorialspots.com/crop/crop.php?src=http://static.php.net/www.php.net/images/php.gif&w=80&h=40&x=20&y=13 we get the result: Example 2: Source picture http://incloak.com/images/proxylist_port_4084543.gif http://www.demo.tutorialspots.com/crop/crop.php?w=5&h=8&x=0&y=3&src=http://incloak.com/images/proxylist_port_4084543.gif we get the result: Continuing…

Read full story Comments { 0 }
PHP: Crop image function

PHP: Crop image function

See our logo Step 1: detect filetype (gif, jpeg, png) use function getimagesize result: array(6) { [0]=> int(300) [1]=> int(107) [2]=> int(3) [3]=> string(24) “width=”300″ height=”107″” [“bits”]=> int(8) [“mime”]=> string(9) “image/png” } Note: Returns a array with 6 elements. The 0 index is the width of the image in pixels. The 1 index is the […]

Read full story Comments { 0 }
Function sys_getloadavg in PHP < 5.1.3

Function sys_getloadavg in PHP < 5.1.3

According to the document of PHP official website, http://php.net/sys_getloadavg sys_getloadavg (PHP 5 >= 5.1.3) sys_getloadavg — Gets system load average So, it’s only for PHP >= 5.1.3. In PHP < 5.1.3, we use this function below: <?php if (!function_exists(‘sys_getloadavg’)) { function sys_getloadavg() { if (@is_readable(‘/proc/loadavg’)) { //Linux if ($fh = @fopen(‘/proc/loadavg’, ‘r’)) { $data = […]

Read full story Comments { 1 }
Function str_ireplace in PHP4

Function str_ireplace in PHP4

According to the document of PHP official website, http://php.net/str_ireplace str_ireplace (PHP 5) str_ireplace — Case-insensitive version of str_replace(). So, it’s only for PHP5+. In PHP4, we use this function below: Example 1: result: array(3) { [0]=> string(29) “If find and change are arrays” [1]=> string(92) “then str_ichange() takes a value from each array and uses […]

Read full story Comments { 0 }
Function stripos in PHP4

Function stripos in PHP4

According to the document of PHP official website, http://php.net/stripos stripos (PHP 5) stripos — Find the position of the first occurrence of a case-insensitive substring in a string So, it’s only for PHP5+. In PHP4, we use this function below:

Read full story Comments { 0 }
Function http_build_query in PHP4

Function http_build_query in PHP4

According to the document of PHP official website, http://php.net/http_build_query http_build_query (PHP 5) http_build_query — Generate URL-encoded query string So, it’s only for PHP5+. In PHP4, we use this function below:

Read full story Comments { 0 }
PHP: function mb_str_split

PHP: function mb_str_split

mbstring provides multibyte specific string functions that help you deal with multibyte encodings in PHP. In addition to that, mbstring handles character encoding conversion between the possible encoding pairs. mbstring is designed to handle Unicode-based encodings such as UTF-8 and UCS-2 and many single-byte encodings for convenience.

Read full story Comments { 0 }