Problems encountered when php is used for wap development_PHP tutorial

WBOY
Release: 2016-07-13 17:34:59
Original
727 people have browsed it

选择自 slamdunk3 的 Blog

1.文件格式
首先要遇到的问题肯定是文件格式,在作web开发时,大家都是用的html或xhtml,到了wap开发时,就得用wml了.什么是wml?大家可以去查更详细的资料,我这里只是略微的提到.在我看来wml类似于xml,有非常严格的格式,在作wap页面时,都得用wml来作为显示.

wml的语法非常简单,在用php作动态输出时,一定要发送一个头信息,标明本页面是wml,而不是别的什么*ml.

header("Content-type: text/vnd.wap.wml; charset="gb2312"");
?>

这里用的字符集是gb2312,在移动的平台上是没有任何问题的,但在联通的平台上就不行了,一定得用utf-8,为了更通用,还是用utf-8更安全.即

header("Content-type: text/vnd.wap.wml; charset="utf-8"");
?>

2.编码

上面说了字符集都应采用utf-8,这是一种容纳了多国语言的字符集,一个汉字是占双字节,utf-8占了4个字节,因此其容纳的信息量更大.在手机上编写的汉字,在将页面内码转成utf-8后,以后再打开就可能是一堆乱码.因此大家在作注释时,尽可能的用英文注释,省得以后看不懂.像editplus,ultraedit等工具都可以转文件内码.

3.适配

世界各大手机厂商真是有病,开发出的手机千奇百怪,可以支持的格式也是五花八门.比如铃声,有的可以支持,16,32,48和弦,支持mid,wmv,有的不完全支持;有的支持gif,png,bmp,有的也不完全支持.这虽然是把手机的档次和成本拉开了,但却苦了作手机开发的兄弟们了.因为不可避免的要对手机所能支持的图片,铃声等多媒体信息作出一个匹配,这个匹配的处理,我们一般叫做手机适配.
要作手机适配,我们一般得有如下资料.

1)一份详细的手机适配资料表,里面应详细的说明手机所能支持的铃声,图片格式,还得有手机型号等信息
2)要正确的获取手机的UA,什么是UA,就是(user agent),实际上就是用户的手机信息.

有了上面的东东我们才能做出适配.以下给出一个我写的在wap开发中用到的类,可以用来取手机号,手机UA.

 /**
* 类名: mobile
* 描述: 手机信息类
* 其他: 偶然 编写
*/
class mobile
{
/**
* 函数名称: getPhoneNumber
* 函数功能: 取手机号
* 输入参数: none
* 函数返回值: 成功返回号码,失败返回false
* 其它说明: 说明
*/
function getPhoneNumber()
{
if (isset($_SERVER[HTTP_X_NETWORK_INFO]))
{
$str1 = $_SERVER[HTTP_X_NETWORK_INFO];
$getstr1 = preg_replace(/(.*,)(11[d])(,.*)/i,,$str1);
Return $getstr1;
}
elseif (isset($_SERVER[HTTP_X_UP_CALLING_LINE_ID]))
{
$getstr2 = $_SERVER[HTTP_X_UP_CALLING_LINE_ID];
Return $getstr2;
}
elseif (isset($_SERVER[HTTP_X_UP_SUBNO]))
{
$str3 = $_SERVER[HTTP_X_UP_SUBNO];
$getstr3 = preg_replace(/(.*)(11[d])(.*)/i,,$str3);
Return $getstr3;
}
elseif (isset($_SERVER[DEVICEID]))
{
Return $_SERVER[DEVICEID];
}
else
{
Return false;
}
}

/**
* 函数名称: getHttpHeader
* 函数功能: 取头信息
* 输入参数: none
* 函数返回值: 成功返回号码,失败返回false
* 其它说明: 说明
*/
function getHttpHeader()
{
$str = ;
foreach ($_SERVER as $key=>$val)
{
$gstr = str_replace("&","&",$val);
$str.= "$key -> ".$gstr." ";
}
Return $str;
}

/**
* 函数名称: getUA
* 函数功能: 取UA
* 输入参数: none
* 函数返回值: 成功返回号码,失败返回false
* 其它说明: 说明
*/
function getUA()
{
if (isset($_SERVER[HTTP_USER_AGENT]))
{
Return $_SERVER[HTTP_USER_AGENT];
}
else
{
Return false;
}
}

/**
* 函数名称: getPhoneType
* 函数功能: 取得手机类型
* 输入参数: none
* 函数返回值: 成功返回string,失败返回false
* 其它说明: 说明
*/
function getPhoneType()
{
$ua = $this->getUA();
if($ua!=false)
{
$str = explode( ,$ua);
Return $str[0];
}
else
{
Return false;
}
}

/**
* 函数名称: isOpera
* 函数功能: 判断是否是opera
* 输入参数: none www.knowsky.com
* 函数返回值: 成功返回string,失败返回false
* 其它说明: 说明
*/
function isOpera()
{
$uainfo = $this->getUA();
if (preg_match(/.*Opera.*/i,$uainfo))
{
Return true;
}
else
{
Return false;
}
}

/**
* Function name: isM3gate
* Function function: Determine whether it is m3gate
* Input parameters: none
* Function return value: Return string if successful, false
* on failure* Other instructions: Description
*/
function isM3gate()
{
$uainfo = $this->getUA();
if (preg_match(/M3Gate/i,$ uainfo))
{
Return true;
}
else
{
Return false;
}
}

/**
* Function name: getHttpAccept
* Function function: Get HA
* Input parameter: none
* Function return value: Return string if successful, false if failed
* Other instructions: Description
*/
function getHttpAccept()
{
if (isset($_SERVER[HTTP_ACCEPT]))
{
Return $_SERVER[HTTP_ACCEPT];
}
else
{
Return false;
}
}

/**
* Function name: getIP
* Function function: Get the mobile phone IP
* Input parameters: none
* Function return value: Successfully returns string
* Other instructions: Description
*/
function getIP()
{
$ip=getenv(REMOTE_ADDR);
$ip_ = getenv(HTTP_X_FORWARDED_FOR);
if ((( $ip_ != "") && ($ip_ != "unknown"))
{
$ip=$ip_;
}
return $ip;
}
}
?>

4. Page design

When developing wap, the wap page is very simple. It cannot be simpler than html. In wap1.0, there are no messy things like tables. All tags are written in Within a tag called card, it can be used for segmentation. So it is easy to create pages.

5. Emulator

Wap development inevitably requires the use of various simulators for testing. The better ones are m3gate, openwave, opera, and one called winwap. It is best not to use it for testing because of its compatibility Great, even if there are errors on the page, they can be ignored. When testing, just like testing a web page with a browser, just enter the URL. There is nothing easier than this.

6. Precautions

1) Space, especially when defining DTD,


echo "";
?>


If there are spaces missing anywhere, you will suffer. When I was writing, I used page rearrangement to remove some spaces. It took me two days to find the error. Everyone Don’t follow in my footsteps.

2) Tags, if the tags are not paired, an error will be prompted. Just pay attention, it is easy to correct.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508380.htmlTechArticleSelected from slamdunk3’s Blog 1. File format The first problem to encounter is definitely the file format when doing web development At that time, everyone used html or xhtml. When it comes to wap development, you have to use wml. What is...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!