Solved

PHP special character string filter

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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.
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 …

707 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

17 Experts available now in Live!

Get 1:1 Help Now