Monday, 15 April 2013

Html Entities and Html special chars

You want to convert the HTML character into their corresponding HTML entities.
FOr that you can Use Functions 
  1. htmlentities ()
  2. htmlspecialchars()
For example ===
Form Having Text area
<form action="" method="POST">
<textarea name="address"></textarea>
<input type="submit" >


PHP part

<?php
$a htmlentities($_POST['address']);
echo $a;

//or 
$b = htmlspecialchars($_POST['address']);
echo $b;

//If you want to convert those entities back into HTML character

echo html_entity_decode($a);

echo "</br>";

echo html_entity_decode($b);


Now if you ask which one will be best then ..

htmlentities() can translate anything as listed in Manual

while htmlspecialchars() translate only specialcharacter

For DEtails Refer These Links

No comments:

Post a Comment