note 55836 deleted from function.preg-split by mazzanet
| From: | mazzanet@php.net | Date: | Mon, 15 Aug 2005 07:05:57 +0000 |
| Subject: | note 55836 deleted from function.preg-split by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-93667@lists.php.net to get a copy of this message | ||
Note Submitter: phphile at no-email dot com/sorry
----
im currentl working on a wap portal, trying to use all sorts of php to seperate and neatly disply
phone makes and models [and version numbers!] but keep getting stuck, here's my script for
nokia:
// we start by asking for the user agent
$user_agent = $HTTP_USER_AGENT;
// now i use a function to change the numbers, i.e. 6230, 3330, to X.
function trim_nok($string)
{
$string = trim($string);
$string = ereg_replace("1","x",$string);
$string = ereg_replace("2","x",$string);
$string = ereg_replace("3","x",$string);
$string = ereg_replace("4","x",$string);
$string = ereg_replace("5","x",$string);
$string = ereg_replace("6","x",$string);
$string = ereg_replace("7","x",$string);
$string = ereg_replace("8","x",$string);
$string = ereg_replace("9","x",$string);
$string = ereg_replace("0","x",$string);
$string = trim($string);
return $string;
}
// next, i'll shave it down to 9 characters long.
$differ = substr($user_agent,0,9);
// trim it to turn numbers to x's with our function above
$trimming = trim_nok("$differ");
// is it a nokia?
if ($trimming == "Nokiaxxxx")
{
if (preg_match ("/Nokia/i", "$user_agent.")) $nokia = "Nokia";
// select matching numbers, end up with a long string
function nokinums($string)
{ preg_match_all('/(?:([0-9]+)|.)/i', $string, $matches);
return strtolower(implode('', $matches[1])); }
// run it through
$modelnokia = nokinums("$user_agent");
// slice it down to 4 characters
$modelnokia = substr($modelnokia,0,4);
// if we know it's "Nokiaxxxx" then we know (well i know) that i can cut from the
fourteenth character of the entire user_agent string and take out 8 characters after the 14...
$ver_nokia = substr($user_agent,14,8);
// trim off those brackets...
function trim_ver($string)
{
$string = ltrim($string);
$string = ereg_replace(")",".",$string);
$string = ereg_replace("\(","v",$string);
$string = trim($string);
return $string;
}
// run the last one through
$vers = trim_ver("$ver_nokia");
// display it.
$nokia_display = "$nokia $modelnokia $vers";
}
it SUCKS man! im stuck, samsung D500s and E330s, yes i can get numbers with the above methods but
not letters!
someone help, please?