note 55836 added to function.preg-split
| From: | phphile at no-email dot com/sorry | Date: | Mon, 15 Aug 2005 04:25:51 +0000 |
| Subject: | note 55836 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93659@lists.php.net to get a copy of this message | ||
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?
----
Manual Page -- http://www.php.net/manual/en/function.preg-split.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55836
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55836&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55836&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55836&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55836&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55836&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55836&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55836&report=yes
Search -- http://master.php.net/manage/user-notes.php