Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2031
  • Last Modified:

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
0
stargateatlantis
Asked:
stargateatlantis
  • 2
1 Solution
 
TheAnarchistCommented:
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

0
 
TheAnarchistCommented:
Correction...remove the double quote from that...otherwise it will preserve those as well...
$my_string = eregi_replace('[^a-z0-9 ]', '', $my_string);

Open in new window

0
 
NicksonKohCommented:
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

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now