Horje
How to clean Strip out HTML and Special Characters in PHP

Here is Probably better here for a regex replace.


Clean HTML Special Characters

It will clean HTML Special Characters.
index.php
Example: PHP
// Strip HTML Tags
$clear = strip_tags($des);
// Clean up things like &
$clear = html_entity_decode($clear);
// Strip out any url-encoded stuff
$clear = urldecode($clear);
// Replace non-AlNum characters with space
$clear = preg_replace('/[^A-Za-z0-9]/', ' ', $clear);
// Replace Multiple spaces with single space
$clear = preg_replace('/ +/', ' ', $clear);
// Trim the string of leading/trailing space
$clear = trim($clear);
$clear = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($des))))));

PHP Strip HTML Tags

index.php
Example: PHP
<?php
$clear = strip_tags($des);
?>

PHP Clean up things like &amp;

index.php
Example: PHP
<?php
$clear = html_entity_decode($clear);
?>

PHP Strip out any url-encoded stuff

index.php
Example: PHP
<?php
$clear = urldecode($clear);
?>

PHP Replace non-AlNum characters with space

index.php
Example: PHP
<?php
$clear = preg_replace('/[^A-Za-z0-9]/', ' ', $clear);
?>

PHP Replace Multiple spaces with single space

<?php
$clear = preg_replace('/ +/', ' ', $clear);
?>

PHP Trim the string of leading/trailing space

<?php
$clear = trim($clear);
?>

PHP Special Tag Replace

index.php
Example: PHP
<?php
$clear = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($des))))));
?>




html string

Type:
Develop
Category:
Web Tutorial
Sub Category:
PHP String Tutorial
Uploaded by:
Admin