Home Backend Development PHP Tutorial PHP作WAP开发时遇到的问题_PHP

PHP作WAP开发时遇到的问题_PHP

Jun 01, 2016 pm 12:34 PM
f return function develop cell phone illustrate return meet question

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."\r\n";
}
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
* 函数返回值: 成功返回string,失败返回false
* 其它说明: 说明
*/
function isOpera()
{
$uainfo = $this->getUA();
if (preg_match('/.*Opera.*/i',$uainfo))
{
Return true;
}
else
{
Return false;
}
}

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

/**
* 函数名称: getHttpAccept
* 函数功能: 取得HA
* 输入参数: none
* 函数返回值: 成功返回string,失败返回false
* 其它说明: 说明
*/
function getHttpAccept()
{
if (isset($_SERVER['HTTP_ACCEPT']))
{
Return $_SERVER['HTTP_ACCEPT'];
}
else
{
Return false;
}
}

/**
* 函数名称: getIP
* 函数功能: 取得手机IP
* 输入参数: none
* 函数返回值: 成功返回string
* 其它说明: 说明
*/
function getIP()
{
$ip=getenv('REMOTE_ADDR');
$ip_ = getenv('HTTP_X_FORWARDED_FOR');
if (($ip_ != "") && ($ip_ != "unknown"))
{
$ip=$ip_;
}
return $ip;
}
}
?>


4.页面设计

作wap开发时,wap页面是非常简单的.比html来说是简单到不能再简单了.在wap1.0里是没有表格之类的乱七八糟的东西的.所有的标签都是写在一个叫card的标签之内.可以用来分段.所以做页面的算是轻松了.

5.模拟器

作wap开发免不了要用各式各样的模拟器来测试,比较好的有m3gate,openwave,opera,还有一个叫winwap的,大家最好别用他来作测试,他的兼容性太好了,即使页面有错误都能给忽略掉.测试时跟用浏览器测试web页面一样,输入网址就可以了.没有比这更容易的事了.

6.注意事项

1)空格,特别是在定义DTD时,


echo "";
?>


里面如果哪个地方少个空格,就有你受的了.以前写的时候用了页面重排之后,把一些空格给干掉了,整整找了两天才找出错误来,大家千万别步我的后尘.

2)标签,如果标签不成对,会提示错误,大家注意就是了,很容易修正.
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
OPPO A3x mobile phone released: equipped with MediaTek Dimensity 6300, 4+128GB version priced at 1199 yuan OPPO A3x mobile phone released: equipped with MediaTek Dimensity 6300, 4+128GB version priced at 1199 yuan Jul 30, 2024 am 01:27 AM

According to news on July 29, in addition to the 1,799 yuan OPPO A3 Vibrant Edition mobile phone, OPPO also launched an A3x (PKD130), available in three colors: starlight white, dark night purple, and cloud feather pink. According to @Perfectly arranged digital, OPPOA3x seems to be an offline model. The main difference from the active version is that the rear lens is replaced with a 32+2MP dual camera. The summary pricing is as follows: 4+128GB version 1199 yuan 6+128GB version 1499 yuan 8+256GB version 1999 yuan 1. Equipped with MediaTek Dimensity 6300 processor, equipped with LPDDR4X memory and UFS2.2 flash memory, supports 2TB storage expansion, adopts 6.67-inch "sunshine screen" , with 1600×720 resolution, 1

Samsung Galaxy S25 Ultra mobile phone leaked: 6.86 inches, horizontal screen-to-body ratio 94.1% Samsung Galaxy S25 Ultra mobile phone leaked: 6.86 inches, horizontal screen-to-body ratio 94.1% Aug 17, 2024 pm 01:49 PM

According to news on August 17, the source @ibinguniverse posted on Weibo today, stating that the exact size of Apple iPhone 16 Pro Max is 6.88 inches, and the exact size of Galaxy S25 Ultra is 6.86 inches. Both can be regarded as 6.9 inches. Sources indicate that the Samsung Galaxy S25 Ultra has a narrower body and a wider screen than the S24 Ultra, with a horizontal screen-to-body ratio of 94.1%, while the S24 Ultra’s horizontal screen-to-body ratio is 91.5%. Fenye checked the relevant Weibo of the source. He also commented on the newly exposed photos of iPhone 16 Pro Max and believed that it was wrong to be close to a micro-curve. The phone is actually a straight screen + 2.5D glass.

'Tandem OLED' has been popularized by Apple. How is it better than OLED? 'Tandem OLED' has been popularized by Apple. How is it better than OLED? Aug 19, 2024 am 04:42 AM

Although Apple has been criticized for its lack of innovation in recent years, Apple has not always stood still. At least in terms of hardware design, with the support of the high unit prices of Apple products, its engineers can easily try some new technologies without having to consider too much cost issues. For example, iPad Pro, as Apple's favorite "display technology" test field, iPad Pro has been at the forefront of display technology for portable smart devices from miniLED in 2021 to tandem OLED in 2024. Although the iPad Pro is not the first portable smart device equipped with a miniLED screen (MSI released a miniLED laptop a year earlier than Apple), when you compare the parameters of the two, you will quickly realize that they are not the same

Hynix is ​​the first to demonstrate UFS 4.1 flash memory: based on V9 TLC NAND particles Hynix is ​​the first to demonstrate UFS 4.1 flash memory: based on V9 TLC NAND particles Aug 09, 2024 pm 03:33 PM

According to news on August 9, at the FMS2024 Summit, SK Hynix demonstrated its latest storage products, including UFS4.1 universal flash memory that has not yet officially released specifications. According to the official website of the JEDEC Solid State Technology Association, the latest UFS specification currently announced is UFS4.0 in August 2022. Its theoretical interface speed is as high as 46.4Gbps. It is expected that UFS4.1 will further improve the transmission rate. 1. Hynix demonstrated 512GB and 1TBUFS4.1 general-purpose flash memory products, based on 321-layer V91TbTLCNAND flash memory. SK Hynix also exhibited 3.2GbpsV92TbQLC and 3.6GbpsV9H1TbTLC particles. Hynix shows off V7-based

Released on August 1, physical photos of Xiaomi POCO M6 Plus 5G mobile phone and POCO Buds X1 headphones exposed Released on August 1, physical photos of Xiaomi POCO M6 Plus 5G mobile phone and POCO Buds X1 headphones exposed Jul 30, 2024 pm 02:29 PM

According to news on July 30, source Yogesh Brar posted a tweet on the X platform yesterday (July 29), sharing physical photos of Xiaomi POCOM6 Plus 5G mobile phone and POCO Buds X1 headphones. The official announcement of the two products will be released on August 1. Xiaomi POCOM6 Plus 5G mobile phone sources said that Xiaomi POCOM6 Plus 5G mobile phone will be equipped with a 6.8-inch LCD screen, equipped with Qualcomm Snapdragon 4Gen2AE processor, equipped with a 108-megapixel camera on the back, and a 5030mAh capacity battery. As previously reported, this phone is available in three colors: purple, black, and silver. It is roughly the same as the standard POCOM6 phone, but the LED flash ring is relatively more prominent. POCOB

The first 1.5K under-screen camera! Nubia Z70 Ultra is here: the world's first Snapdragon 8 Gen4 true full-screen phone The first 1.5K under-screen camera! Nubia Z70 Ultra is here: the world's first Snapdragon 8 Gen4 true full-screen phone Aug 19, 2024 pm 03:47 PM

According to news on August 19, Nubia has been adhering to the true full-screen design since the release of Z50 Ultra, and has been continuously exploring the field of proactive photography under high-pixel screens. Today, digital blogger Wisdom Pikachu broke the news that the Nubia Z70 Ultra, which will be released in the second half of this year, will debut with 1.5K under-screen camera technology, which is the highest-resolution UDC solution in the industry so far. It is reported that ZTE’s under-screen proactive solution has advanced to the sixth generation. The latest under-screen proactive solution is available in the Nubia Z60 Ultra and Red Magic 9S Pro series. The screen resolution is 2480x1116, which is between 1080P and 1.5K resolution. This time Nubia will break through the limitations of existing resolutions and set a new benchmark in the industry.

To run Google's Gemini Nano AI model locally, the Samsung Galaxy S25 Ultra phone was revealed to be equipped with 16GB of memory To run Google's Gemini Nano AI model locally, the Samsung Galaxy S25 Ultra phone was revealed to be equipped with 16GB of memory Jul 31, 2024 pm 05:55 PM

According to news on July 31, the source @ibinguniverse posted a tweet on the Equipped with 16GB of memory. Samsung mobile phone memory capacity update Samsung has launched 16GB memory on Galaxy S20 Ultra and Galaxy S21 Ultra mobile phones. Starting from Galaxy S22 Ultra, including the latest flagship Galaxy S24 Ultra mobile phone, the memory capacity of Samsung mobile phones is capped at 12GB. It is reported that the upcoming Samsung Galaxy S25 and Galaxy S25+ will use 12GB LPDD

Produced by Ningde New Energy Technology Company, Samsung Galaxy S25 Ultra mobile phone battery exposed Produced by Ningde New Energy Technology Company, Samsung Galaxy S25 Ultra mobile phone battery exposed Jul 31, 2024 pm 04:57 PM

According to news on July 31, technology media SamMobile published a blog post yesterday (July 30) and found battery information suitable for Samsung Galaxy S25 Ultra mobile phones on the SafetyKorea certification website. According to the public information, the battery models exposed this time are EB-BS938ABY and EB-BS938ABE. It is not yet clear what the difference between the two models is. fenye Samsung Galaxy S25 Ultra mobile phone will not use the dual battery solution of Galaxy Z Fold6 and Galaxy Z Flip 6 folding mobile phones, but will adopt a single battery design. It has been previously reported that Samsung will not upgrade and optimize the battery specifications of the Galaxy S25 Ultra mobile phone, and will still use

See all articles