PHP foreach loop

foreach loop give us easy way to iterate over array. foreach loop only works with arrays. Syntax: foreach (array_expression as $value) statement foreach (array_expression as $key => $value) statement Example: <?php $array = array(1, 2, 3, 4, 5, 6); foreach($array as $value) {    echo $value; } ?> Another Example: <?php $array = array(7, 8,...

Read more »

PHP – USPS Shipping Rate

The following php code helps you get the live shipping rate from USPS server. Code Example: index.php usps-class.php

Read more »

PHP – UPS Shipping Rate

The following php code helps you get the live shipping rates of UPS server. Code Example: index.php ups-class.php

Read more »

PHP File

The following actions can be performed on a file: Modes Description r   Read only Starts from beginning of the file r+  Read/Write Starts from beginning of the file w   Write only Opens and clears the contents of file; or creates a new file if it doesn't exist w+  Read/Write...

Read more »

PHP for Loop

The for loop can be used when you know in advance how many times the script should run. Syntax: for(initiate; condition; increment){    code to be executed; } Example: <?php for($i=1; $i<=10; $i++){    echo "The value of \$i is " . $i . "<br />";? } ?> Infinite...

Read more »

PHP while Loop

The PHP while loop executes a block of code until a condition is true. syntax: while(condition){    code to be executed; } Example: <?php $i=1; while($i<=10){    echo "The value of \$i is " . $i . "<br />";    $i++; } ?> Infinite while loop: while(1){}  // that...

Read more »

Send Email using Simple PHP function

The function is use to send an email directly form the script: <?php $to = "test@example.com"; // sender $subject = "Testing email"; $message = "Hi! This is a simple email testing message."; $from = "someone@example.com"; // receiver $headers = "From: $from"; if(mail($to,$subject,$message,$headers)){    echo "Mail Successfully Sent."; } else{...

Read more »

explode()

PHP explode is use for split a string. <?php $dolls  = "doll1 doll2 doll3 doll4 doll5"; $array_dolls = explode(" ", $dolls); echo $array_dolls; // doll1 echo $array_dolls; // doll2 ?>

Read more »

implode()

Join array elements with a string implode. <?php $array = array('name', 'address', 'phone'); $comma_separated = implode(",", $array); echo $comma_separated; // name,address,phone ?>

Read more »

Convert special HTML entities back to characters htmlspecialchars_decode

This function is the opposite of htmlspecialchars(). It converts special HTML entities back to characters. <?php $str = '<p>this -&gt; "</p>'; echo htmlspecialchars_decode($str); // note that here the quotes aren't converted echo htmlspecialchars_decode($str, ENT_NOQUOTES); ?>

Read more »

Convert special characters to HTML entities htmlspecialchars

Convert the special characters into HTML entities. <?php $new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES); echo $new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt; ?>

Read more »

Get protocol number associated with protocol name getprotobyname

Returns the protocol number or -1 if the protocol is not found. <?php $protocol = 'tcp'; $get_prot = getprotobyname($protocol); if($get_prot == -1) { echo 'Invalid Protocol'; } else{ echo 'Protocol #' . $get_prot; } ?>

Read more »

Gets time of last page modification getlastmod ( )

Gets the time of the last modification of the current page. <?php // outputs e.g. 'Last modified: March 04 1998 20:43:59.' echo "Last modified: " . date("F d Y H:i:s.", getlastmod()); ?>

Read more »