Link to home
Start Free TrialLog in
Avatar of stargateatlantis
stargateatlantis

asked on

Replace all characters except Numbers Letters and space

Using ereg_replace I want to replace all HTML characters the only characters i want is ALPHA Numeric and space
Avatar of TheAnarchist
TheAnarchist

This will remove anything that is not a letter, a number, or a space.
$my_string = eregi_replace('[^a-z0-9 "]', '', $my_string);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TheAnarchist
TheAnarchist

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

You can also try the preg_replace which is often faster than ereg_replace.

I am not sure if you need to use multiline mode. If yes, just change expression to

$pattern = '/[^a-z0-9\s]/im';
<?php
$string = 'yourHTML';
$pattern = '/[^a-z0-9\s]/i';
$replacement = '';
echo preg_replace($pattern, $replacement, $string);
?>

Open in new window