TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-20-2009, 03:08 AM   #1 (permalink)
The Wanderer
 
superthin's Avatar
 
Join Date: Aug 2008
Posts: 16
Thanks: 7
superthin is on a distinguished road
Default Give me remove special characters from a string, plz

Hello everybody,

I am a newbie. I want to remove all special characters from a string (keep alpha-numeric character only). And replace a space (or many spaces) with "-" character.

Code:
Ex: This is bullshit M$ Word. They make   me 100% crazy.
Will be: This-is-bullshit-M-Word-They-make-me-100-crazy
Any help will be appreciated. Thanks in advance.

Best regards,
SuperThin.
__________________
http://khoancatbetong.com - Vietnamese Concrete Technician Forum
superthin is offline  
Reply With Quote
Old 07-20-2009, 03:19 AM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

This should do it
PHP Code:
// To strip special chars
preg_replace("[!-@]","",$subject);

//To make all spaces -
str_replace(" ","-",$subject);

//Take any sequince of two or more -s and make them one.
preg_replace("[-]{2,}","-",$subject); 
I wrote this off the top of my head, so I can't guarantee that its perfect.
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
superthin (07-20-2009)
Old 07-20-2009, 11:13 AM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You could also use a single call to preg_replace with multiple patterns/replacements.

PHP Code:
$subject 'This is bullshit M$ Word. They make   me 100% crazy.';
$search  = array('/[^a-z0-9 ]+/i''/ +/');
$replace = array('''-');
echo 
preg_replace($search$replace$subject);
// Output: This-is-bullshit-M-Word-They-make-me-100-crazy 
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
superthin (07-20-2009)
Old 07-29-2009, 12:51 AM   #4 (permalink)
The Wanderer
 
superthin's Avatar
 
Join Date: Aug 2008
Posts: 16
Thanks: 7
superthin is on a distinguished road
Default

Wow, thank you(s) very much. Now, I want to "Do not replace . (point) / Point is not a special character". What should I do? It seems to very hard to grasp Regular Expression for beginners.
__________________
http://khoancatbetong.com - Vietnamese Concrete Technician Forum
superthin is offline  
Reply With Quote
Old 07-29-2009, 10:04 AM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Just change [^a-z0-9 ] in my previous post to [^a-z0-9. ]. Simples.

As for learning regular expressions, if you haven't already then please bookmark and visit http://www.regular-expressions.info/ as it is the best concise online source of information about regular expressions that I've found so far.
Salathe is offline  
Reply With Quote
Old 10-18-2012, 12:46 PM   #6 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Some conservatives have Coach Factory Outlet pushed that critique further, saying that Mr. Obama’s policies are too costly, often assist the wrong people Louis Vuitton Belts and could have the paradoxical effect of driving up college costs. The dispute turns not just on different Coach Factory Outlet assessments of how policies play out, but on differing philosophical views about the role of government. During Gucci Belts his time in office, Mr. Obama has sharply increased aid to low- and middle-income students, notably through the Pell Grant Coach Factory Outlet program, which grew from $14.6 billion given to 6 million students in 2008, to nearly $40 billion for Coach Factory Outlet almost 10 million students this year. His administration also made it easier to request aid, shortening the Coach Factory Online complex federal application and allowing people to transfer their financial information electronically from the Internal Coach Outlet Online Revenue Service database. But while many education experts laud his efforts, analysts of varying political Coach Outlet Online stripes have also questioned how much impact some of the president’s policies will have, noting that the prices Coach Online Outlet charged by colleges, and student borrowing, continue to climb.But behind the headlines about soaring costs, the Coach Factory Outlet Online reality is more complex and wildly uneven, because a growing number of students receive Coach Outlet Online financial aid, and only relatively high-income families pay those fast-rising sticker prices. Adjusted for Coach Factory Online inflation, the College Board calculates, the average net price changed little over the last decade at private Coach Factory Outlet schools, and rose only modestly at public ones.Defending federal spending, Arne Duncan, the secretary of Hermes Belts education, said that for more than 30 years, college prices had risen even when federal aid had not, leading him to believe Coach Factory Online there was zero correlation.
dashixiong is offline  
Reply With Quote
Old 10-22-2012, 08:49 AM   #7 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default Coach Outlet

You’ve relativelyCoach Outlet recently arrived in New Delhi after living in two of Asia’s other great cities,Coach Outlet Store Online Tokyo and Hong Kong, for several years. Do these cities feel like they’re part of the same continent? Yes, and no. In terms Coach Factory Onlineof infrastructure, they couldn’t be more different. Getting regularCoach Outlet power and water at my house in New Delhi is never a sure thing, even though Coach Purse Outlet OnlineI’m paying the same rent that I paid in Tokyo and almost the same electricity prices. Both Hong Kong and Tokyo are also crowded places,Coach Factory Outlet Online but both cities are incredibly well planned and efficiently run. Efficient is not a word I would use to describe my Coach Bags Outlet Onlineday-to-day life in New Delhi. On the other hand, one thing that I think Hong Kong and New Delhi have in common isCoach Handbags Outlet a shared sense of optimism — a feeling that the best is yet to come. That’s definitely not the feeling you get in Tokyo,Coach Outlet Online or in the U.S. when I go home. It’s a big part of what I find addictive about living and working in this part of the world. You feel like you’re watching the future unfold.
dashixiong is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting special characters in LIKE (mySQL) ReSpawN Advanced PHP Programming 2 11-12-2012 07:44 AM
add special characters to DB? arale Absolute Beginners 0 07-08-2009 04:33 AM
Special to plain characters ReSpawN Advanced PHP Programming 3 05-27-2009 10:33 AM
array elements into variables and values Dave Absolute Beginners 7 06-20-2008 01:56 PM
remove from string... how to do? Sam Granger Absolute Beginners 2 12-04-2007 08:17 AM


All times are GMT. The time now is 01:44 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design