[nycphp-talk] Trim
harvey
list at harveyk.com
Tue Nov 23 10:18:32 EST 2004
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; }
More information about the talk
mailing list