[nycphp-talk] Trim
harvey
list at harveyk.com
Tue Nov 23 11:30:12 EST 2004
Thanks. With a little tweaking, I think I got the code you referenced to work.
At Tuesday 11/23/2004 10:22 AM, Ben Ramsey wrote:
>Try this link and see if it helps you easily capture the phone number data:
>http://benramsey.com/archive/cat/making_it_valid/making_it_valid_telephone_numbers.php
>
>Then, after using the code at that link, just do:
>$newphone = $area_code . '-' . $exchange . '-' . $number;
>
>That should do it for you.
>
>
>harvey wrote:
>>Hi, I'm trying to 'normalize' phone numbers that are submitted via a
>>form, so that they all appear as xxx-xxx-xxxx. I'm sure there's a more
>>elegant way of doing it, but the following seems to work-- almost. But
>>the trim part does not actually trim. I'm sure it has something to do
>>with the type/case of the content submitted or the quotation marks or
>>something like that. If I replace the GetSQL statement with ' (212)
>>555-1212 ', it works fine. I tried dropping the GetSQL and just using
>>the $_Post, tried putting single and double quotes, etc. Any ideas? Thanks!
>> $phone = GetSQLValueString($_POST['phone'],"text");
>> $phone = trim($phone);
>> $replace = array (") ","."," ");
>> $newphone = str_replace($replace,"-",$phone);
>> $newphone = str_replace("(","",$newphone);
>>
>>This is the GetSQLValueString function that Dreamweaver creates
>>automatically:
>>function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
>>$theNotDefinedValue = "")
>>{ $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
>> switch ($theType) {
>> case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" :
>> "NULL"; break;
>> case "long":
>> case "int": $theValue = ($theValue != "") ? intval($theValue) :
>> "NULL"; break;
>> case "double": $theValue = ($theValue != "") ? "'" .
>> doubleval($theValue) . "'" : "NULL"; break;
>> case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" :
>> "NULL"; break;
>> case "defined": $theValue = ($theValue != "") ? $theDefinedValue :
>> $theNotDefinedValue; break; }
>> return $theValue; }
>
>--
>Ben Ramsey
>Atlanta PHP
>http://atlphp.org
>http://benramsey.com
>_______________________________________________
>New York PHP Talk
>Supporting AMP Technology (Apache/MySQL/PHP)
>http://lists.nyphp.org/mailman/listinfo/talk
>http://www.newyorkphp.org
More information about the talk
mailing list