Solved

PHP special character string filter

Posted on 2007-03-21
5
343 Views
Last Modified: 2013-12-13
I need an all encompassing statement to remove all special characters, commas, and any other non url sype characters. Also id like it to turn all white spaces to _

an example would be

This is great, and easy too!!!----*_*_

to

This_is_great_and_easy_too

I also need to filter out any of the special odd characters that are sometimes generated
0
Comment
Question by:lexshine
[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
  • 3
  • 2
5 Comments
 

Author Comment

by:lexshine
ID: 18762787
by special characters i mean this type of stuff:
’s
0
 

Author Comment

by:lexshine
ID: 18762796
an added bonus would be if the routine turned multiple spaces into one:

this     is too many spaces

this_is_too_many_space
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18762857
Something like:

<?php

$s = 'This is great, and easy too!!!----*_*_';

$s = preg_replace(array('/[^a-z\d ]/is', '/\s+/s'), array('', '_'), $s);

echo $s;

?>
0
 

Author Comment

by:lexshine
ID: 18762914
very very nice!

what about dealing with stuff like. its encoded in some of the strings I am dealing with

Cindy&#39;s &quot;Road&quot; makes...

0
 
LVL 29

Accepted Solution

by:
TeRReF earned 500 total points
ID: 18763233
Okay, then you can do something like:

<?php

$s = 'This is great, and easy too!!!----*_*_';

$s = preg_replace(array('/[^a-z\d ]/is', '/\s+/s'), array('', '_'), html_entity_decode($s));

echo $s;

?>
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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