Solved

Replace all characters except Numbers Letters and space

Posted on 2008-10-12
3
2,016 Views
Last Modified: 2013-11-10
Using ereg_replace I want to replace all HTML characters the only characters i want is ALPHA Numeric and space
0
Comment
Question by:stargateatlantis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Expert Comment

by:TheAnarchist
ID: 22700023
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
 
LVL 6

Accepted Solution

by:
TheAnarchist earned 500 total points
ID: 22700024
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
 
LVL 17

Expert Comment

by:NicksonKoh
ID: 22700078
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question