Problems encountered during WAP development in PHP

Source: Internet
Author: User
1. the first problem with the file format must be the file format. during web development, everyone uses html or xhtml, and wml is used for wap development. what is wml? You can check more detailed information, which I just mentioned here. in my opinion, wml is similar to xml and has a very strict format. wml is used for display on wap pages. wml syntax is very 1. file format
The first problem to be encountered must be the file format. during web development, we all use html or xhtml. when we get to wap development, we have to use wml. what is wml? You can check more detailed information, which I just mentioned here. in my opinion, wml is similar to xml and has a very strict format. wml is used for display on wap pages.

The wml syntax is very simple. when using php for dynamic output, you must send a header to indicate that this page is wml, rather than anything else * ml.


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



The character set used here is gb2312. there is no problem on the mobile platform, but it won't work on the platform of China Unicom. we must use UTF-8 to make it more common, it is safer to use UTF-8. that is


Header ("Content-type: text/vnd. wap. wml; charset = \" UTF-8 \"");
?>



2. encoding

As mentioned above, all character sets should adopt utf-8. this is a character set that can accommodate multiple languages. one Chinese character occupies dual bytes and UTF-8 occupies four bytes. Therefore, it can hold a larger amount of information. after converting the webpage code into UTF-8, a bunch of garbled characters can be opened later. therefore, when you make comments, try to use English comments as much as possible, saving you from understanding them later. tools such as editplus and ultraedit can convert the file internal code.

3. adaptation

Mobile phone manufacturers all over the world are really ill-intentioned. the various formats supported by mobile phones are also varied. for example, ringtones, some support, 16, 32, 48 chords, mid, wmv, and some do not fully support; some support gif, png, bmp, and some do not. although this is to open up the mobile phone grade and cost, but it is bitter for mobile phone development Brothers. because it is inevitable to make a match for the pictures, ringtones, and other multimedia information supported by the mobile phone. this matching process is generally called mobile phone adaptation.
For mobile phone adaptation, we generally need the following materials.

1) a detailed mobile phone adaptation data table that describes the ringtones, image formats, mobile phone models, and other information supported by mobile phones.
2) correctly obtain the UA of the mobile phone. what is UA is actually the user agent.

With the above stuff, we can make adaptation. The following is a Class I wrote in wap development, which can be used to get the mobile phone number and the mobile phone UA.


/**
* Class name: mobile
* Description: mobile phone information.
* Others: accidental writing
*/
Class mobile
{
/**
* Function name: getPhoneNumber
* Function: obtains the mobile phone number.
* Input parameter: none
* Function return value: the number is returned successfully. if the function fails, false is returned.
* Other instructions: Description
*/
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;
}
}

/**
* Function name: getHttpHeader
* Function: obtains the header information.
* Input parameter: none
* Function return value: the number is returned successfully. if the function fails, false is returned.
* Other instructions: Description
*/
Function getHttpHeader ()
{
$ Str = '';
Foreach ($ _ SERVER as $ key => $ val)
{
$ Gstr = str_replace ("&", "&", $ val );
$ Str. = "$ key->". $ gstr. "\ r \ n ";
}
Return $ str;
}

/**
* Function name: getUA
* Function: UA
* Input parameter: none
* Function return value: the number is returned successfully. if the function fails, false is returned.
* Other instructions: Description
*/
Function getUA ()
{
If (isset ($ _ SERVER ['http _ USER_AGENT '])
{
Return $ _ SERVER ['http _ USER_AGENT '];
}
Else
{
Return false;
}
}

/**
* Function name: getPhoneType
* Function: obtains the mobile phone type.
* Input parameter: none
* Function return value: string is returned for success, and false is returned for failure.
* Other instructions: Description
*/
Function getPhoneType ()
{
$ Ua = $ this-> getUA ();
If ($ ua! = False)
{
$ Str = explode ('', $ ua );
Return $ str [0];
}
Else
{
Return false;
}
}

/**
* Function name: isOpera
* Function: determines whether it is opera.
* Input parameter: none
* Function return value: string is returned for success, and false is returned for failure.
* Other instructions: Description
*/
Function isOpera ()
{
$ Uainfo = $ this-> getUA ();
If (preg_match ('/. * Opera. */I', $ uainfo ))
{
Return true;
}
Else
{
Return false;
}
}

/**
* Function name: ismreceivate
* Function: determines whether it is mshortate.
* Input parameter: none
* Function return value: string is returned for success, and false is returned for failure.
* Other instructions: Description
*/
Function ismreceivate ()
{
$ Uainfo = $ this-> getUA ();
If (preg_match ('/mshortate/I', $ uainfo ))
{
Return true;
}
Else
{
Return false;
}
}

/**
* Function name: getHttpAccept
* Function: obtain the HA
* Input parameter: none
* Function return value: string is returned for success, and false is returned for failure.
* Other instructions: Description
*/
Function getHttpAccept ()
{
If (isset ($ _ SERVER ['http _ ACCEPT '])
{
Return $ _ SERVER ['http _ ACCEPT '];
}
Else
{
Return false;
}
}

/**
* Function name: getIP
* Function: obtain the mobile IP address.
* Input parameter: none
* Function return value: string is returned successfully.
* 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

During wap development, the wap page is very simple. it is simpler than html. in wap1.0, there are no tables or other things in disorder. all labels are written in a card label. it can be used for segmentation. therefore, page creation is easy.

5. Simulator

For wap development, it is inevitable to use a variety of simulators for testing. the better ones are m3gate, openwave, opera, and winwap. we 'd better not use it for testing. Its compatibility is too good, ignore the error even if the page has an error. during the test, you can enter the website address just like testing the web page with a browser. nothing is easier.

6. Notes

1) space, especially when defining a DTD,


Echo "";
?>


If there is less space in it, you will get it. I used to re-arrange pages and killed some spaces when I wrote them. it took me two days to find out the error. please do not follow me.

2) labels. if the tags are not paired, an error will be prompted. you should pay attention to them and it is easy to correct them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.