Results from the most recent live auction are here .
17 members in the live chat room. Join Chat !
System Maintenance: NamePros will be offline for 20 minutes at the top of the hour (4AM EST)
04-15-2008, 01:03 PM
· #1 NamePros Member
I want to remove non standard characters from form input
Hello,
What can i do to remove unwanted characters from form? I want to have numbers european letters and punctuation marks.
I just want to remove everything else.
Thanks
04-15-2008, 04:57 PM
· #2 NamePros Regular
Name: Trevor
Location: Atlanta, GA, USA
Join Date: Feb 2006
PHP Code:
<?php
if (!isset( $_POST [ 'submit' ])){ ?>
<form action="" method="POST" >
Input : <input type="text" name="input" /><br />
<input type="submit" value="POST" name="submit"/>
</form>
<?php } else {
$data = $_POST [ 'input' ];
$newdata = '' ;
for ( $x = 0 ; $x <= strlen ( $data ); $x ++) {
$char = substr ( $data , $x , 1 );
$ascii = ord ( $char );
$newdata .= $ascii >= 32 && $ascii <= 122 ? $char : '' ;
}
echo $newdata . '<br><br>' ;
}
?>
04-15-2008, 05:43 PM
· #3 Law and disorder
Name: Kate
Location: Expat
Join Date: Aug 2005
Posts: 5,456
NP$: 1547.11 (
Donate )
Use a regular expression like this (untested).
PHP Code:
$text = $_POST [ 'text' ];
$text = preg_replace ( "/[^a-z0-9-\.:,;]/i" , "" , $text );
so everything that does not match a thru z or punctuation like . , ; : is replaced with an empty string.
04-16-2008, 01:43 AM
· #4 NamePros Regular
Name: Derek
Location: Seattle, Wa
Join Date: Jul 2004
Posts: 597
NP$: 69.00 (
Donate )
Originally Posted by Kath Use a regular expression like this (untested).
PHP Code:
$text = $_POST [ 'text' ];
$text = preg_replace ( "/[^a-z0-9-\.:,;]/i" , "" , $text );
so everything that does not match a thru z or punctuation like . , ; : is replaced with an empty string.
Sorry if I'm incorrect, (I'm not very good with regular expressions), but shouldn't A-Z be included in the statement or else capital letters will be erased.
04-16-2008, 02:09 AM
· #5 NamePros Regular
Join Date: Mar 2007
Posts: 874
NP$: 205.58 (
Donate )
/i is flag to ignore case, so no need to add A-Z
-
__________________ Patience is your best friend in this business! (© by Gene)
04-16-2008, 05:05 AM
· #6 The original NP Emo Kid
Name: Liam Dawe
Location: Plymouth, UK
Join Date: Jan 2005
Posts: 1,577
NP$: 124.00 (
Donate )
Originally Posted by zoki /i is flag to ignore case, so no need to add A-Z
-
Exactly so it ignored everything there, A-Z is not in there so it will not ignore it, and replace?
04-16-2008, 10:37 AM
· #7 NamePros Regular
Name: Derek
Location: Seattle, Wa
Join Date: Jul 2004
Posts: 597
NP$: 69.00 (
Donate )
Originally Posted by zoki /i is flag to ignore case, so no need to add A-Z
-
Oh ok, thanks.
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off