Solved

PHP special character string filter

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

785 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