Thursday, June 27, 2013

htmlentities & htmlspecialchars in php

htmlentities 

Convert all applicable characters to HTML entities

$str = "A 'quote' is <b>bold</b>";

Example
echo htmlentities($str);
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;



htmlspecialchars 

Convert special characters to HTML entities

'&' (ampersand) becomes '&amp;' 
'<' (less than) becomes '&lt;' 

Example
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; //Outputs:  &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;

(Uniform Resource Locator ) urlencode & urldecode in php

urlencode & urldecode in php

urlencode  — This function returns the string output

URL is converted into a valid ASCII format.
URL Encoding space is replaced by %20

Example
urlencode('Hello milind') return output ==>> Hello%20milind 

another example
urlencode('http://www.mywebsite.com/index.php?name=milind chaudhari&id=25');

Output is http://www.mywebsite.com/index.php?name=milind%20chaudhari&id=25


urldecode  — This function returns the string output
Decodes URL-encoded string

Returns the decoded string.

Example
urldecode('http://www.mywebsite.com/index.php?name=milind%20chaudhari&id=25');

Output
http://www.mywebsite.com/index.php?name=milind chaudhari&id=25

Saturday, June 1, 2013

Create Cron job/Task scheduler on windows local machine

For developer , It is most important to run the specific program for specific time of interval on local machine (localhost).
It can be done with the help of task scheduler

For Task schedular Go to the Start >> All programs >> Accessories >> System Tools >> Task Scheduler

Then click on Create Task
Fill all the details, please add the .bat file and complete the process.
Please specify the commands in to your .bat file.

In that .Bat file

D:\xampp\php\php.exe -f "D:\xampp\htdocs\mysqlbackup.php"


In mysqlbackup.php

$dbhost = "localhost"; // usually localhost
$dbuser = "root";
$dbpass = "";
$dbname = "Db_name";

$backupfile = 'E:/'.$dbname . date("Y-m-d") . 'todayDb.sql';
 system("D:/xampp/mysql/bin/mysqldump.exe -h $dbhost -u $dbuser $dbname > $backupfile");