Solved

PHP special character string filter

Posted on 2007-03-21
5
313 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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.

867 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

15 Experts available now in Live!

Get 1:1 Help Now