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 12-03-2009, 02:28 AM   #1 (permalink)
The Contributor
 
Join Date: Apr 2008
Location: Nevada, USA
Posts: 52
Thanks: 10
h0ly lag is on a distinguished road
Default Stripping non alpha numeric characters

This should work correct?

PHP Code:
ereg_replace('[^A-Za-z]',''$str); 
Because I am using it on a project that I need to strip any characters that are not alpha numeric, or if the string contains dash's or underscores that is ok too. But I can add that in later. I guess my problem is that It's not stripping '^' or '#'. I'm sure there are more characters its letting through. But those are the ones I've noticed so far.
__________________
Send a message via AIM to h0ly lag Send a message via MSN to h0ly lag
h0ly lag is offline  
Reply With Quote
Old 12-03-2009, 04:10 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

You should avoid using ereg_replace() - the ereg_* set of functions have been deprecated in favor of the PCRE equivalent preg_* set. They're also much slower.

With that out of the way, it should work.

php Code:
$string = 'This $is a #test ~of ^the non-alphanumeric preg_replace';
echo preg_replace( '~[^A-Za-z0-9\s\-_]~', '', $string );
delayedinsanity is offline  
Reply With Quote
Old 12-03-2009, 06:13 AM   #3 (permalink)
The Contributor
 
Join Date: Apr 2008
Location: Nevada, USA
Posts: 52
Thanks: 10
h0ly lag is on a distinguished road
Default

Oh dang. I should know that about ereg. I just read that the other day. and thank you very much. I know if I ever have a problem you guys are always super friendly at TalkPHP. :) Thanks again.
__________________
Send a message via AIM to h0ly lag Send a message via MSN to h0ly lag
h0ly lag 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
Dingo Framework - ALPHA Testing Open! ETbyrne Show Off 97 10-18-2012 02:11 PM
add special characters to DB? arale Absolute Beginners 0 07-08-2009 04:33 AM
PHP 5.3 Alpha 1 Released Kalle The Lounge 1 08-01-2008 08:09 PM
Alpha testers wanted delayedinsanity The Lounge 13 07-19-2008 09:31 PM
Cleaning out unwanted characters Andrew General 6 10-20-2007 08:31 PM


All times are GMT. The time now is 05:32 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