Subscribe For Free Updates!

We'll not spam mate! We promise.

Aug 14, 2013

Create directory with current year and month name - php

Create directory with current year and month name - php :
 

  Here i will explain about how to create folder / directory with the current year and month name. It is very usefull to seperate the uploaded image or file with the particular year and month name.

Here we will use the simple concept to create this. here date() function is used to get current year and month details.

For Example :

  if (!file_exists("techniq/".date('Y').'/'.date('m'))) {
    mkdir("techniq/".date('Y').'/'.date('m'), 0777, true);
   }

  In the above example three php pre defined function are used. that is file_exists() , date() , mkdir().

1. file_exists() :- This function is used to check the given path for directory is available or not. It will return bool value. If the file exists then it will return TRUE otherwise FALSE.

2. date() :- This function is used to get current timestamp. here i used date('Y'), it will return current year in numeric i.e., 2013. and date('m') return current month in the format of 08.

   Note : Read more about date() : http://techniqzone.blogspot.in/2013/07/php-to-get-yesterdayprevious-date.html

3. mkdir() :- This function is used to create a directory with the give filename or path. here i used 0777 argument for set folder permission for the created directory.

This method is easy to create Folder(directory) with current Year and Month name in php.

Aug 13, 2013

Export particular column data from table in phpmyadmin


Export particular column data from table in phpmyadmin :

 Here i will explain how to export particular column data from table. we can store the output in .sql or .csv file. In this method the output data will store in a file with newline (\n) separaters.

The syntax is :

SELECT column_name FROM table_name INTO OUTFILE '/opt/lampp/htdocs/fileName.sql'

The above syntax is store the output file in .sql format. you can change the format what you need. In the below example i will make the ooutput file in .csv format.

Example :

SELECT second_name FROM employee INTO OUTFILE '/opt/lampp/htdocs/secondName.csv'

Note : Best to download output file with .csv format. because .csv file format import has many advanced option when we import data to db. you can export with CSV, .zip, .gzip, etc... format.



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.