RSS Feed
Jan 12

PHP-mysql_real_escape_string()

Posted on Tuesday, January 12, 2010 in Php / mySql

Escapes special characters in the unescaped_string , taking into account the current character set of the connection so that it is safe to place it in a mysql_query(). If binary data is to be inserted, this function must be used.

mysql_real_escape_string() calls MySQL’s library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ‘, ” and \x1a.

Sep 13

HTML tags to print on page by htmlspecialchars function

Posted on Sunday, September 13, 2009 in Php / mySql

We can display some special chars especially html tags on the screen by using htmlspecialchars function of PHP. This is required when we have to show some sample codes on the page or screen. For example I want to display this line

if ($i < 5 )
Here we can't write < as it is , in this place I have to write < then while displaying this will display < on the screen. Same way some other chars are there which are to be written in different way or special care to be taken for displaying them. All these jobs can be done by using htmlspecialchars function.

This function takes care of &, < ( less than ), > ( greater than ), ” double quote ( if ENT_NOQUOTES is not set. ) and single quote (only when ENT_QUOTES is set). Single quote became ' and double quote became ". Same way < ( less than ) became < and > ( greater than ) became >

Now let us try with an example.

Read this line below, we want to display the formatting of this line.

Hello this is bold This is italic This is normal this is a double quote ” this is & this is less than < this is greater than >

The html part of the above line is here
Hello this is bold This is italic This is normal this is a double quote ” this is & this is less than < this is greater than >
Now to display the code for the above line formatted in different style we have to use htmlspecialchars funciton like this
$contents=”Hello this is bold This is italic This is normal this is a double quote ” this is & this is less than < this is greater than >“;
echo htmlspecialchars($content);