| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Webmaster ![]() ![]() ![]() Join Date: Feb 2003
Posts: 12,930
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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? |
| |
| | #2 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | #4 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | no probs -RJ- glad to be of assistance.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
| | #9 (permalink) |
| NamePros Regular Join Date: Feb 2004 Location: Student @ UConn
Posts: 411
![]() ![]() | 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 |
| |
| | #10 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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:
__________________ 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.
|
| |
![]() |
| 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 |