Source for file DoCoMo.php
Documentation is available at DoCoMo.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: KUBO Atsuhiro <kubo@isite.co.jp> |
// +----------------------------------------------------------------------+
// $Id: DoCoMo.php,v 1.24 2005/08/18 07:18:04 kuboa Exp $
require_once(dirname (__FILE__ ) . '/Common.php');
require_once(dirname (__FILE__ ) . '/Display.php');
require_once(dirname (__FILE__ ) . '/DoCoMoDisplayMap.php');
* NTT DoCoMo implementation
* Net_UserAgent_Mobile_DoCoMo is a subclass of
* {@link Net_UserAgent_Mobile_Common}, which implements NTT docomo i-mode
* require_once('Net/UserAgent/Mobile.php');
* $_SERVER['HTTP_USER_AGENT'] = 'DoCoMo/1.0/P502i/c10';
* $agent = &Net_UserAgent_Mobile::factory();
* printf("Name: %s\n", $agent->getName()); // 'DoCoMo'
* printf("Version: %s\n", $agent->getVersion()); // 1.0
* printf("HTML version: %s\n", $agent->getHTMLVersion()); // 2.0
* printf("Model: %s\n", $agent->getModel()); // 'P502i'
* printf("Cache: %dk\n", $agent->getCacheSize()); // 10
* if ($agent->isFOMA()) {
* print "FOMA\n"; // false
* printf("Vendor: %s\n", $agent->getVendor()); // 'P'
* printf("Series: %s\n", $agent->getSeries()); // '502i'
* // only available with <form utn>
* // e.g.) 'DoCoMo/1.0/P503i/c10/serNMABH200331';
* printf("Serial: %s\n", $agent->getSerialNumber()); // 'NMABH200331'
* // e.g.) 'DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)';
* printf("Serial: %s\n", $agent->getSerialNumber()); // '0123456789abcde'
* printf("Card ID: %s\n", $agent->getCardID()); // '01234567890123456789'
* // e.g.) 'DoCoMo/1.0/P502i (Google CHTML Proxy/1.0)'
* printf("Comment: %s\n", $agent->getComment()); // 'Google CHTML Proxy/1.0'
* // e.g.) 'DoCoMo/1.0/D505i/c20/TB/W20H10'
* printf("Status: %s\n", $agent->getStatus()); // 'TB'
* // only available in eggy/M-stage
* // e.g.) 'DoCoMo/1.0/eggy/c300/s32/kPHS-K'
* printf("Bandwidth: %dkbps\n", $agent->getBandwidth()); // 32
* @package Net_UserAgent_Mobile
* @author KUBO Atsuhiro <kubo@isite.co.jp>
* @version $Revision: 1.24 $
* @see Net_UserAgent_Mobile_Common
* @link http://www.nttdocomo.co.jp/p_s/imode/spec/useragent.html
* @link http://www.nttdocomo.co.jp/p_s/imode/tag/imodetag.html
* @link http://www.nttdocomo.co.jp/p_s/imode/tag/utn.html
* @link http://www.nttdocomo.co.jp/p_s/mstage/visual/contents/cnt_mpage.html
* name of the model like 'P502i'
* status of the cache (TC, TB, TD, TJ)
* bandwidth like 32 as kilobytes unit
* hardware unique serial number
var $_serialNumber = null;
* whether it's FOMA or not
* FOMA Card ID (20 digit alphanumeric)
* comment on user agent string like 'Google Proxy'
* cache size as killobytes unit
* width and height of the display
* parse HTTP_USER_AGENT string
* @return mixed void, or a PEAR error object on error
@list ($main, $foma_or_comment) =
&& preg_match('/^\((.*)\)$/', $foma_or_comment, $matches)
// DoCoMo/1.0/P209is (Google CHTML Proxy/1.0)
$this->_comment = $matches[1 ];
$result = $this->_parseMain ($main);
} elseif ($foma_or_comment) {
// DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)
$result = $this->_parseFOMA ($foma_or_comment);
$result = $this->_parseMain ($main);
* create a new {@link Net_UserAgent_Mobile_Display} class instance
* @return object a newly created {@link Net_UserAgent_Mobile_Display}
* @see Net_UserAgent_Mobile_Display
* @see Net_UserAgent_Mobile_DoCoMoDisplayMap::get()
if ($this->_displayBytes !== '') {
list ($widthBytes, $heightBytes) =
explode('*', $this->_displayBytes);
$display['width_bytes'] = $widthBytes;
$display['height_bytes'] = $heightBytes;
* returns supported HTML version like '3.0'. retuns null if unknown.
if (!isset ($htmlVersionMap)) {
'502i|821i|209i|651|691i|(F|N|P|KO)210i|^F671i$' => '2.0',
'(D210i|SO210i)|503i|211i|SH251i|692i|200[12]|2101V' => '3.0',
'504i|251i|^F671iS$|212i|2051|2102V|661i|2701|672i|(SO213i|SO213iS)' => '4.0',
'505i|252i|900i|506i|880i|253i|P213i|901i|700i|851i' => '5.0'
foreach ($htmlVersionMap as $key => $value) {
* returns cache size as kilobytes unit. returns 5 if unknown.
return $this->_cacheSize;
static $defaultCacheSize;
if (!isset ($defaultCacheSize)) {
return $defaultCacheSize;
* returns series name like '502i'. returns null if unknown.
if (preg_match('/(\d{3}i)/', $this->_model, $matches)) {
if ($this->_model == 'P651ps') {
* returns vender code like 'SO' for Sony. returns null if unknown.
if (preg_match('/([A-Z]+)\d/', $this->_model, $matches)) {
* returns name of the model like 'P502i'
* returns status like "TB", "TC", "TD" or "TJ", which means:
* TC | Browsers with image off (only Available in HTML 5.0)
* returns bandwidth like 32 as killobytes unit. Only vailable in eggy,
* returns null otherwise.
return $this->_bandwidth;
* returns hardware unique serial number (15 digit in FOMA, 11 digit
* otherwise alphanumeric). Only available with form utn attribute.
* returns null otherwise.
return $this->_serialNumber;
* retuns whether it's FOMA or not
* returns comment on user agent string like 'Google Proxy'. returns null
* returns FOMA Card ID (20 digit alphanumeric). Only available in FOMA
* with <form utn> attribute. returns null otherwise.
if (!isset ($gpsModels)) {
$gpsModels = array ('F661i', 'F505iGPS');
return in_array($this->_model, $gpsModels);
// {{{ getCarrierShortName()
* returns the short name of the carrier
// {{{ getCarrierLongName()
* returns the long name of the carrier
* parse main part of HTTP_USER_AGENT string (not FOMA)
* @param string $main main part of HTTP_USER_AGENT string
* @return mixed void, or a PEAR error object on error
function _parseMain ($main)
@list ($this->name, $this->version, $this->_model, $cache, $rest) =
if ($this->_model === 'SH505i2') {
$this->_model = 'SH505i';
$this->_cacheSize = (integer) $matches[1 ];
foreach ($rest as $value) {
if (preg_match('/^ser(\w{11})$/', $value, $matches)) {
$this->_serialNumber = $matches[1 ];
if (preg_match('/^(T[CDBJ])$/', $value, $matches)) {
$this->_status = $matches[1 ];
$this->_bandwidth = (integer) $matches[1 ];
if (preg_match('/^W(\d+)H(\d+)$/', $value, $matches)) {
$this->_displayBytes = "{ $matches[1 ]}*{ $matches[2 ]}";
* parse main part of HTTP_USER_AGENT string (FOMA)
* @param string $foma main part of HTTP_USER_AGENT string
* @return mixed void, or a PEAR error object on error
function _parseFOMA ($foma)
$this->_model = $matches[1 ];
if ($matches[1 ] === 'MST_v_SH2101V') {
$this->_model = 'SH2101V';
if (preg_match('/^[^(]+\((.*?)\)$/', $foma, $matches)) {
foreach ($rest as $value) {
$this->_cacheSize = (integer) $matches[1 ];
if (preg_match('/^ser(\w{15})$/', $value, $matches)) {
$this->_serialNumber = $matches[1 ];
if (preg_match('/^(T[CDBJ])$/', $value, $matches)) {
$this->_status = $matches[1 ];
if (preg_match('/^icc(\w{20})$/', $value, $matches)) {
$this->_cardID = $matches[1 ];
if (preg_match('/^W(\d+)H(\d+)$/', $value, $matches)) {
$this->_displayBytes = "{ $matches[1 ]}*{ $matches[2 ]}";
* c-hanging-comment-ender-p: nil
Documentation generated on Mon, 11 Mar 2019 14:16:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|