NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Seeking php function to strip invalid characters from string

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-24-2005, 02:42 AM THREAD STARTER               #1 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness
 



Find Marrow Donors! Cystic Fibrosis Parkinson's Disease

Seeking php function to strip invalid characters from string


I'm looking for the most efficient function that I can give a string and have it return the same string without the invalid characters. Its for a domain related application so only alphanumeric and hyphens are valid.

Example:
$string = cleanstring("test_ing"); # returns "testing"
$string = cleanstring("t@e#s%t i*n^g"); # returns "testing"
$string = cleanstring("test-ing"); # returns "test-ing"

Suggestions?
__________________
@DomainBuyer facebook
RJ is offline  
Old 03-24-2005, 10:01 AM   #2 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
wouldnt you just be as well to do :-

$domain_name = preg_replace('/[^a-zA-Z0-9/-]/','',$domain_name);
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 03-24-2005, 10:27 AM THREAD STARTER               #3 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness
 



Find Marrow Donors! Cystic Fibrosis Parkinson's Disease
Originally Posted by filth
wouldnt you just be as well to do :-

$domain_name = preg_replace('/[^a-zA-Z0-9/-]/','',$domain_name);
That's what I needed. Thanks Peter!
__________________
@DomainBuyer facebook
RJ is offline  
Old 03-24-2005, 01:36 PM   #4 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
no probs -RJ- glad to be of assistance.
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 03-31-2005, 04:02 PM THREAD STARTER               #5 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness
 



Find Marrow Donors! Cystic Fibrosis Parkinson's Disease
I'm getting this error

Warning: Unknown modifier '-' in /script.php on line 85

Using this line
$domain_name = preg_replace('/[^a-zA-Z0-9/-]/','',$domain_name);
__________________
@DomainBuyer facebook
RJ is offline  
Old 03-31-2005, 04:36 PM   #6 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



are the variables right? You had $string in your first post, but now it is $domain_name - is this right?
PoorDoggie is offline  
Old 03-31-2005, 04:41 PM THREAD STARTER               #7 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness
 



Find Marrow Donors! Cystic Fibrosis Parkinson's Disease
Variable name shouldn't matter, but my actual code is

$sld = preg_replace('/[^a-zA-Z0-9/-]/','',$sld);

I think I just need a refresher on regular expressions.
__________________
@DomainBuyer facebook
RJ is offline  
Old 03-31-2005, 04:51 PM   #8 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



sorry can't help you then. I just use cleanstring()
PoorDoggie is offline  
Old 03-31-2005, 05:06 PM   #9 (permalink)
NamePros Regular
Join Date: Feb 2004
Location: Student @ UConn
Posts: 411
gamex has a spectacular aura aboutgamex has a spectacular aura about
 



It seems that if you remove the / before the -, the error goes away, but I dont know if thats still what you want. I never really got the hang of reg exps so sorry if that wasnt what you were looking for
__________________
Joe
gamex is offline  
Old 04-01-2005, 12:34 AM   #10 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
yes my bad I escaped the - when it wasnt needed. RJ you can just delete the / before the - and it will work

Poordoggie cleanstring() is not an in built php function but I presume you mean

PHP Code:
function cleanString($wild) {
????: NamePros.com http://www.namepros.com/programming/77410-seeking-php-function-strip-invalid-characters.html
   return 
ereg_replace("[^[:alnum:]+]","",$wild);

which is in a note by one of the users at php.net
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Last edited by filth; 04-01-2005 at 12:37 AM.
Peter is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 12:35 PM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 10:09 AM
Tutorial: A Basic intro to using PHP GD functions to generate and manipulate images. deadserious Webmaster Tutorials 3 12-10-2003 12:42 AM
Executing a php function with onClick web guru Programming 3 09-29-2003 09:34 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:32 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger