Blog Details

Home Blogs

blog-img01

PHP

PHP

Memcached Working with PHP
Description
<?php

/*=======connect Memcache===============*/ 

        $m = new Memcache;     

  $m->connect('localhost', 11211) or die ("Could not connect"); 

  $expires = 60*60*24*30; // seconds, minutes, hours, days 

  $data[] = (object) array('UnitId'=>'1', 'UnitName'=>'pic'); 

  $data[] = (object) array('UnitId'=>'2', 'UnitName'=>'bundle'); 

  $arr['rows']=$data; 

  $str=json_encode($arr);  

  /*=======Memcache Object Ready=========*/ 

  //echo $str; 

  $obj = new stdClass;   

  $obj->str = $str; 

  /*=======Set Memcache Obj==============*/ 

  $m->set('key', $obj, false, $expires );     

  /*=======Delete Memcache Obj===========*/ 

  //$m->delete('key');             

  /*=======Fetch Memcache Obj============*/ 

  $get_result = $m->get('key');         

  /*=======Print Memcache JSON obj=======*/ 

  echo $get_result->str;     

    

?>

List of all Column in a MySql Table
Description
<?php

  $host_name='localhost'; 

  $db_name="dgfplmis_db"; 

  $UserID="root"; 

  $Password=""; 

  $connection=mysql_connect($host_name,$UserID,$Password) or die("Could not connect to server"); 

  $db=mysql_select_db($db_name,$connection) or die("Could not select database"); 

  $sql="SHOW COLUMNS FROM `2012_f7_tab` "; 

  $result=mysql_query($sql,$connection); 

  while($row=mysql_fetch_assoc($result)){     

    $arr[]=$row['Field']; 

    //print_r($row); 

  } 

  echo json_encode($arr); 

    

?>

List of All Files in a Directory
Description
<?php

//path to directory to scan 

$directory = "images/project1/620x378/"; 

//get all image files with a .jpg extension. 

$images = glob($directory . "*.jpg"); 

//print each file name 

foreach($images as $image) 

{ 

echo $image; 

} 

    

?>

XML Generation
Description
<?php

header(“Content-type: text/xml”);

$str= “<?xml version=’1.0′ encoding=’ISO-8859-1′?>”;

$str.= “<note>”;

$str.= “<from>Nayeem</from>”;

$str.= “<to>Fariha</to>”;

$str.= “<message>Remember me this weekend</message>”;

$str.= “</note>”;

echo $str;

?>

PHP E-mail Sending
Description
<?php

$to .= ‘
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
‘;

// subject

$subject = ‘Birthday Reminders for August’;

// message

$message = ‘

<html> <head> <title>Birthday Reminders for August </head>

<body> <p>Here are the birthdays upcoming in August!</p> <table> <tr> <th>Person</th><th>Day</th><th>Month</th><th>Year</th> </tr> <tr> <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> </tr> </table>

</body> </html> ‘;

// To send HTML mail, the Content-type header must be set

$headers = ‘MIME-Version: 1.0’ . “\r\n”;

$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;

// Additional headers

$headers .= ‘To: Mary <
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
>, Kelly <
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
>’ . “\r\n”;

$headers .= ‘From: Birthday Reminder <
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
>’ . “\r\n”;

$headers .= ‘Cc:
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
‘ . “\r\n”;

$headers .= ‘Bcc:
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
‘ . “\r\n”;

// Mail it

mail($to, $subject, $message, $headers);

?>

Leave a Reply

Your email address will not be published. Required fields are marked *