Archive | PHP

RSS feed for this section
PHP function: get US state name by abbreviation

PHP function: get US state name by abbreviation

This is a state list I made for a website. I kept it just in case i ever needed it again, which i have. I figured it would probably help someone else out. It includes all states in the US and two “51st state” (Puerto Rico and Guam). There are some functions that return the […]

Read full story Comments { 0 }
PHP function: Image Resize and Crop

PHP function: Image Resize and Crop

This function support crop and resize JPEG, GIF, PNG image. Example of usage: online demo

Read full story Comments { 0 }
Simple Poll script with PHP and MySQL

Simple Poll script with PHP and MySQL

This tutorial will demonstrate how to make a basic poll using PHP, and store the results in MySQL DEMO: HERE

Read full story Comments { 0 }
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: Convert Numeric Character Reference to UTF8

PHP: Convert Numeric Character Reference to UTF8

Some functions to convert Numeric Character Reference (NCR) to UTF8: Method 01 Ex: Result: La Fenêtre de Soleil Alternative methods: Method 02 Method 03 Ex: result: Peut être Next: PHP: Convert Numeric Character Reference to UTF8 – Part 2

Read full story Comments { 1 }
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 }