Subscribe For Free Updates!

We'll not spam mate! We promise.

Jul 31, 2013

PHP - To Check Query Process

PHP - To Check Query Process:

 Here i will explain how to check the mysql query processing by using php. This function shows you which threads are running.

Here i'm using "SHOW FULL PROCESSLIST" mysql command. This command is very useful if you get the "too many connections" error message and want to find out what is going on. The output shows the current running threads process id. You can use that id to kill that process.

php program is:

mysql_connect("localhost","root",""); // here we set localhost, username and password

$q = mysql_query("SHOW FULL PROCESSLIST"); // here we run the mysql query

echo "<table border='1'>";

while($l = mysql_fetch_row($q) ) {
echo "<tr>";
foreach($l as $val)
echo "<td>$val </td>";
echo "</tr>";

}
echo "</table>";

mysql_close();

Note : The "SHOW FULL PROCESSLIST" command only shows you which
threads are running. If you do not use the FULL keyword, only the first 100 characters of each statement are shown in the Info field.

Jul 30, 2013

PHP to get yesterday(previous) date


PHP to get yesterday(previous) date:

Here are some methods to get the previous date using php. i.e.,)
yesterday date.
Here date() function is used and "D d-M-Y" format is used, it will
return the date format like "MON 29-Jul-2013".

Let we go to some examples to get the yesterday date in php.

1. echo date("D d-M-Y", time() - 60 * 60 * 24);

2. $pDate = new DateTime();
$pDate->add(DateInterval::createFromDateString('yesterday'));
echo $pDate->format('D d-M-Y');

3. echo date("D d-M-Y", strtotime("yesterday"));

4. echo date("D d-M-Y", strtotime('-1 days'));

5. echo date('D d-M-Y', time() - 86400);

6. echo date("D d-M-Y", mktime(0, 0, 0, date("m") , date("d")-1,date("Y")));


These all are return the date in same format like "MON 29-Jul-2013";

If you want some other date format then consider the below examples.

date("D d-M-Y"); // TUE 30-Jul-2013
date("F j, Y, g:i a"); // July 30, 2013, 3:10 pm
date("m.d.y"); // 07.30.13
date("j, n, Y"); // 30, 7, 2013
date("Y-m-d H:i:s"); // 2013-07-30 11:22:14
date('h-i-s, j-m-y, it is w Day'); // 03-10-41, 30-07-13, 2031
2045 2 Tueam13
date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 30th day.
date("D M j G:i:s T Y"); // Tue Jul 30 11:21:03 CEST 2013
date('H:m:s \m \i\s\ \m\o\n\t\h'); // 11:07:36 m is month
date("H:i:s"); // 11:21:48
date("Ymd"); // 20130730

Here you can see the attribute are used in date() function is "D,d,m,y,Y,M,H,m,s,i,a,A".
so you can modify it as what format you want like "date(D d/m/Y)". etc...

If you have any queries comments it. Sorry for my poor english.

Jul 14, 2013

Increase Import Maximum file size in phpmyadmin

Increase Import Maximum file size in phpmyadmin










                   Here are the steps to increase the import file size in phpmyadmin. Usually phpmyadmin allows to import sql files maximum of 2M (i.e 2,048kb). To increase the maximum file size do the following changes in php.ini file.


If you are using  windows ,the php configuration file can be located in your server (wampp or xampp) -> php folder.

Find
 upload_max_filesize =2M
in the file,
change the value acording to your need. Here I changed the value to 10M i.e , it allows to import sql files maximum of 10 Mb.

upload_max_filesize = 10M

 

Replace MS Word single quotes in PHP

Replace MS Word single quotes in PHP:
Replace MS Word single quotes in PHP

 The following function is used to replace Microsoft-encoded quotes in PHP.

function replaeQuotes($str) 

    $str1 = array(chr(145),chr(146), chr(147), chr(148), chr(151)); 
    $str2 = array("'", "'",'"','"','-'); 
    return str_replace($str1, $str2, $str); 
}

For Ex:

In php,

 $str="'This is TechniqZone'-For Developers";
$clearStr=replaeQuotes($str);

Remove MS Word special character symbol in html

Remove MS Word special character symbol in html :

 To remove the MS Word special character in html page or website page you just add the bellow header meta tag in your header field.

<META http-equiv="Content-type" content="text/html; charset=iso-8859-1">

Note: In some case the above meta tag will work individually, ie.,) No need to add any other meta tag with this.

Remove MS Word special character symbol in html

Jul 11, 2013

PHP Remove HTML tags from a String

PHP Remove HTML tags from a String :

PHP Remove HTML tags from a String

 The following code is used to remove the html tags from string.

<?php

$input="Hi this is <b>TechniqZone</b>";
$text = strip_tags($input, "");
echo $text;
?>

Output is Hi this is TechniqZone.

The above code remove all html tags from string.


Here strip_tags() function is used to remove tags from string.

string strip_tags ( string $str [, string $allowable_tags ] )


$allowable_tags - You can use the optional second parameter to specify tags which should not be stripped.



<?php

$input="Hi this is lt;a href='http://techniqzone.blogspot.in'><b>TechniqZone</b>lt;/a>";
$text = strip_tags($input, "<b>");
echo $text;
?>


Output is Hi this is TechniqZone. 

Here i allowed <b> tag from string.




Display Current Indian Standard Time using PHP

Display Current Indian Standard Time using PHP :
display indian standard time php


 The following code is used to get the current indian standard time using php.
here the default_timezone_set() function is used to set the country to set the particular time or date of that country.


<?php
date_default_timezone_set('Asia/Calcutta');
echo date("h:i a");
?>

Output of above code is :

06:40 pm

if you want capital letters of am/pm then you just use date("h:i A"). This will return 06:40 PM.

Jul 10, 2013

Php to convert UTC time to local time

Php to convert UTC time to local time
Php to convert UTC time to local time






 Here is a simple code to convert UTC time to local time in php. The $dateInLocal displays the UTC time as localtime.


$time = strtotime($dateInUTC.' UTC');
$dateInLocal = date("Y-m-d H:i:s", $time);
echo $dateInLocal;



Jul 9, 2013

Attachment in mail using PHP

Attachment in mail using PHP



In the previous post, I described HTML content in mails. In this post we can see how attachment in mails can be done using PHP .




$to = 'youraddress@example.com';
//define the subject of the email
$subject = 'Test email with attachment';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-
Content-Type: multipart/alternative; boundary="PHP-alt-"

--PHP-alt-
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

--PHP-alt-
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

TechniqZone Is Help To Guide Developers issues



This is something with HTML formatting.

--PHP-alt---

--PHP-mixed-
Content-Type: application/zip; name="attachment.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment


--PHP-mixed---

//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

Jul 8, 2013

PHP to Determine Page Execution Time

PHP to Determine Page Execution Time :


PHP to Determine Page Execution Time


The below code is used to find the php page execution time.


Just paste the below code in header portion in php page.

<?php 
   $time = microtime(); 
   $time = explode(" ",$time); 
   $time = $time[1] + $time[0]; 
   $starttime = $time; 
;?> 

after the above code you can add other html or php codes.

and paste the below code in footer page of same php file.

<?php 
   $time = microtime(); 
   $time = explode(" ",$time); 
   $time = $time[1] + $time[0]; 
   $endtime = $time; 
   $totaltime = ($endtime - $starttime); 
   echo "This page execution time is ".$totaltime." seconds"; 
;?>

Jul 7, 2013

Sending Nice HTML Email with PHP


Sending Nice HTML Email with PHP :





   Everyone wishes to include Html content in their mails. Here is a sample code to send a mail with HTML content. You can edit the HTML content as you prefer.


$to = 'sample@example.com';

$subject = 'Sample HTML content';

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = '<h1>';';
$message .= '<a href='http://techniqzone.blogspot.in/'>TechniqZone</a> Is Help To Guide Developers issues.';
$message .= '</h1>';
mail($to, $subject, $message, $headers);


$message contains HTML content. And the HTML content will be executed in the mail.

PHP Get Last 12 Months


PHP to get last 12 months : 

 The following coding is used to get previous 12 months by using PHP.



<?php

for ($t = 1; $t <= 12; $t++) {
    echo date("F Y m", strtotime( date( 'Y-m-01' )." -$t months"));
    echo "<br />";
}

?>

 Output of this code is :

June 2013 06
May 2013 05
April 2013 04
March 2013 03
February 2013 02
January 2013 01
December 2012 12
November 2012 11
October 2012 10
September 2012 09
August 2012 08
July 2012 07



 Here date "F Y m" is used to make the date format in above format. you can store these dates in arrat also by using below code.


<?php
for ($t = 1; $t <= 12; $t++) {
    $mnt[]= date("F Y m", strtotime( date( 'Y-m-01' )." -$t months"));
}
?>


Here $mnt is php array variable with last 12 months.