Solved

Replace all characters except Numbers Letters and space

Posted on 2008-10-12
3
2,011 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
  • 2
3 Comments
 
LVL 6

Expert Comment

by:TheAnarchist
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to count occurrences of each item in an array.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now