About phptuts

Author Archive | phptuts
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 }
Function str_split in PHP4

Function str_split in PHP4

According to the document of PHP official website, http://php.net/manual/en/function.str-split.php str_split (PHP 5) str_split — Convert a string to an array

Read full story Comments { 0 }
PHP CURL class support basic authorization, HTTP SOCKS5 proxy and much more

PHP CURL class support basic authorization, HTTP SOCKS5 proxy and much more

This is a useful class written by me and use it regularly. Features HTTPS connection Basic authorization, HTTP proxy SOCKS5 proxy Cookie jar and much more… For some usage, you can read more: PHP & CURL: step by step

Read full story Comments { 1 }
PHP & CURL: step by step

PHP & CURL: step by step

After you read this article: Getting data without risking death with PHP, CURL, you’ve seen the power of CURL. I’ll write more about CURL to introduce a useful PHP class written by me and use it regularly. But first let’s take a CURL research through the examples, step by step: Example 1: GET, include response […]

Read full story Comments { 0 }
PHP: Methods to encrypt and decrypt with private key (part 3)

PHP: Methods to encrypt and decrypt with private key (part 3)

Please read PHP: Methods to encrypt and decrypt with private key (part 1) PHP: Methods to encrypt and decrypt with private key (part 2) Method 3: use xor encryption Example usage: result: It isn’t a nice result, we need to convert to a nice result: base64_encode Result: AAAAAAAAExoFFhsXRA== unpack Result: 000000000000131a05161b1744 To decrypt, we use […]

Read full story Comments { 0 }