Php

Get week dates of current month

Fetch current week days

$year=date("Y"); $month=date('m'); $datee=strtotime("$curr_yea-$curr_mon"); $cur_end=date("Y-m-d",strtotime("+1 month -1 second",$datee));//date("Y-m-t", strtotime("-1 now") ) ; $end = new DateTime("$cur_end"); $endTimestamp = $end->getTimestamp(); $now = new DateTime("$curr_yea-$curr_mon-01"); $now->setTime(0,0); if (($now->format("l") == "Saturday") || ($now->format("l") == "Sunday")) $d = $now; else $d = $now; $oneday = new DateInterval("P1D"); $sixdays = new DateInterval("P6D"); $res =  ..

How to get last date of month

Last date of the month

How to get last date of the month in php <?php $year=date("Y"); $month=date('m'); $datee=strtotime("$curr_yea-$curr_mon"); $cur_end=date("Y-m-d",strtotime("+1 month -1 second",$datee)); echo $cur_end; ?> The above php code will help you to fetch last date of the month. fetch last date of the year.  ..

Fetch blob image type mysql

Display the BLOB image in php

How to fetch blob datatype from mysql useing php. $result = mysql_query($MainSQL,$link); $row =mysql_fetch_array($result,MYSQL_BOTH); $data = $row[0]; echo "<img src='data:image/jpeg;base64," . base64_encode($data) . "' />"; The images are stored in mysql Database as blob type. They can be fetched from mysql database and displayed in php using above code.  ..

Fetch mysql rows recursively in array

Using while loop and recursive array

How to fetch mysql database rows using while loop recursively in an array? function fetchArray(){ $qry = "select name,age from employee"; $res = mysql_query($qry); while($row[]=@mysql_fetch_array($res)); $row = @array_filter($row); } We can now use : $employee_array = fetchArray(); foreach($employee_array as $employee){ echo $employee[0]['name'].' : '.$employee[0]['age'].''; }   ..

Shuffle numbers in between given range

Php code to shuffle numbers

The code given below will work to shuffle numbers in the given range. <?php $num = range(1, 10); // To range between a number 1 to 10 shuffle($num); // To Shuffle a number in 1 to 10 foreach ($num as $no) { echo "$no"; // To display a number  ..

How to sendmail using phpmailer class

Phpmailer class

Download phpmailer class and use the below code to sendmail using php include_once 'class.phpmailer.php'; $subject = "hi"; $msg = "hello"; $mail = new PHPMailer(); $mail->IsMail(); $mail->From = "from@example.com" $mail->Subject = $subject; $mail->AddAddress("to@example.com"); $mail->IsHTML(true); $mail->Body=$msg; if($mail->Send()){ echo "Sent"; } else{ echo "Not Sent"; } You can use the above code to  ..

How to connect with memcache

How to use memcache

How to create new memcache object? The below code will help you to create new memcache object and use the same object for further usage. $memcache_comm_obj = new Memcache; $memcache_comm_obj->connect('127.0.0.1',11211) or die ("Could not connect"); You can use the above memcache object for further memcache operations.  ..

Split string after specific length

String Manipulation after specific length

Split string into two section after specific length, String split 2 sections: This code is not split words. <?php $para="W3calculator, a leading business service based company."; if(strlen($para) > $length) { echo "Before :".$para; $para_title1 = substr($para, 0,strpos($para, ' ', $length)); $para_title2 = split( $para_title1 , $para); echo  ..

Send free sms api gateway integration

SMS gateway integration

<div style='margin:0 auto;width:300px;'> <?php if($_POST){ $ch = curl_init(); $user=""; // here to use Username & password for mvaayoo.com for ex 'test@gmail.com:test2012' $receipientno=$_POST['phno']; // To send whose no $msgtxt=$_POST['msg']; // Here your message $senderID="TEST SMS"; curl_setopt($ch,CURLOPT_URL, "http://api.mVaayoo.com/mvaayooapi/MessageCompose"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&senderID=$senderID&receipientno=$receipientno&msgtxt=$msgtxt"); $buffer = curl_exec($ch); if(empty  ..

Mobile url annotation in desktop sitemaps

Mobile url annotation

Follow the below given annotation to showcase the mobile website url of the same desktop page <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <url> <loc>http://www.example.com/page-1/</loc> <xhtml:link rel="alternate" media="only screen and (max-width: 640px)" href="http://m.example.com/page-1" /> </url> </urlset> Similarly, rel="canonical" tag on the mobile URL should still be added to the mobile page's  ..

Code to get country state city from ipaddress

Php code to get country state and city from ipaddress

If you want to get country ,state and city from ipaddress following the steps 1) Download the simple html dom file from google 2) Give your ipaddress in $ipaddr variable 3) include the simple html dom file in your own file. $ipaddr="xx.abc.123.ra";//$_SERVER['REMOTE_ADDR']; include_once('./simple_html_dom.php'); $urll="http://whoisthisip.com/$ipaddr"; $html = file_get_html("$urll"); $whohtml=array(); $w=0;   ..

Find number of jpg files in a directory

Find total number of image files

Find number of image files in a directory using php, $directory = "directory name"; if (glob($directory . "*.jpg") != false) { $filecount = count(glob($directory . "*.jpg")); echo $filecount; } The above script will help you to find the count or total number of jpg files in a directory  ..

Function array unique

Remove duplicate values in a array

The below script helps you to remove duplicate values in a array <?php $remove_duplicate=array('calc',"math","calc"); print_r($remove_duplicate); echo "Script to remove duplicate values"; print_r(array_unique($remove_duplicate)); // array_unique! ?> OUTPUT: Array ( [0] => calc [1] => math [2] => calc ) Script to remove duplicate values Array ( [0] => calc [1] => math ) In the above script the calc word which  ..

How to find file and directory

Script to list directory content

<?php /* function that reads directory content and returns the result as links to every file in the directory also it display type whether its a file or directory */ function DirDisply() { $TrackDir=opendir("."); echo ""; while ($file = readdir($TrackDir)) { if ($file == "." || $file == "..") { } else {   ..

GLOB_ONLYDIR function

List all the base directories in linux os

<?php $directories = glob($somePath . '/*' , GLOB_ONLYDIR); print_r($directories); ?> OUTPUT: Array ( [0] => /bin [1] => /boot [2] => /cgroup [3] => /dev [4] => /etc .... ) The above is a sample output. The above code is used to print the directories using php code.   ..

Previous 1 2 3 4 5 Next

Tech Bluff