PHP for WAP development problems encountered

Source: Internet
Author: User
Keywords PHP for WAP development problems encountered

Choose a Blog from Slamdunk3

1. File format
The first thing to encounter is certainly the file format, in the Web development, everyone is the use of HTML or XHTML, to the WAP development, you have to use WML. What is WML? You can check more detailed information, I just mention it slightly. In my opinion, WML is similar to XML, There is a very strict format, in the WAP page, you have to use WML as a display.

WML syntax is very simple, when using PHP for dynamic output, it is necessary to send a header message, indicating that this page is WML, and not something 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 on the platform of the Unicom is not, must be used utf-8, in order to more general, or with utf-8 more secure. That

Header ("CONTENT-TYPE:TEXT/VND.WAP.WML; Charset=\ "utf-8\" ");
?>

2. Encoding

It says that the character set should be Utf-8, which is a multi-lingual character set, a Chinese character is a double byte, and the Utf-8 account for 4 bytes, so it can hold more information. Chinese characters written on the phone, after the code in the page is turned into Utf-8, It may be a bunch of garbled characters when you open it later. So when you make comments, as far as possible in English comments, save later do not understand. Tools like Editplus,ultraedit can be transferred to the file inside the code.

3. Adaptation

The world's major mobile phone manufacturers are really sick, developed a variety of mobile phones, can support a variety of formats. such as ringtones, some can support, 16,32,48 chords, support mid,wmv, some do not fully support; some support gif,png,bmp, Some of them are not fully supported. Although this is the grade and cost of mobile phones, but it is hard for mobile phone development of the brothers. Because it is inevitable that the mobile phone can support images, ringtones and other multimedia information to make a match, this matching processing, we are generally called mobile phone adaptation.
To make a mobile phone fit, we generally have to have the following information.

1) A detailed mobile phone adaptation data sheet, which should be detailed description of the phone can support the ringtone, picture format, but also have mobile phone models and other information
2) to get the UA of the phone correctly, what is UA, is (user agent), is actually the user's mobile phone information.

With the above things we can make the adaptation. The following is a list of what I wrote in the WAP development used in the class, can be used to take the mobile phone number, mobile phone UA.

/**
* class Name: Mobile
* Description: Cell phone Information class
* Other: Accidental writing
*/
Class mobile
{
/**
* Function Name: Getphonenumber
* function Can: Take the phone number
* Input parameters: None
* Function return value: Successful return number, failed to return false
* Other Instructions: Description
*/
Function Getphonenumber ()
{
if (isset ($_server[' Http_x_network_info '))
{
$str 1 = $_server[' Http_x_network_info ');
$getstr 1 = preg_replace ('/(. *,) (11[d]) (,. *)/I ', ', $str 1);
Return $getstr 1;
}
ElseIf (isset ($_server[' http_x_up_calling_line_id '))
{
$getstr 2 = $_server[' Http_x_up_calling_ Line_id '];
Return $getstr 2;
}
ElseIf (isset ($_server[' http_x_up_subno '))
{
$str 3 = $_server[' http_x_up_subno '];
$getstr 3 = preg_replace ('/(. *) (11[d]) (. *)/I ', ', $str 3);
Return $GETSTR 3;
}
ElseIf (isset ($_server[' DEVICEID '))
{
Return $_server[' DEVICEID '];
}
Else
{
Return false;
}
}

/**
* Function Name: Gethttpheader
* Function Function: Take header information
* Input Parameters: None
* Function return Value: Successful return number, failed return false
* 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 function: Take UA
* Input Parameters: None
* Function return Value: Successful return number, failed return false
* Other Instructions: description
*/
function Getua ()
{
if (Isset ($_server[' http_user_agent '))
{
Return $_server[' http_user_agent '];
}
Else
{
Return false;
}
}

/**
* Function Name: Getphonetype
* Function function: Get phone type
* Input Parameters: None
* Function return Value: String returned successfully, failure returned false
* Other Instructions: description
*/
function Getphonetype ()
{
$ua = $this->getua ();
if ($ua!=false)
{
$str = Explode (' ', $ua);
Return $str [0];
}
Else
{
Return false;
}
}

/**
* Function Name: Isopera
* Function Function: Judge whether it is opera
* Input parameters: none www.cncms.com
* Function return Value: String returned successfully, failure returned false
* Other Instructions: description
*/
function Isopera ()
{
$uainfo = $this->getua ();
if (Preg_match ('/.*opera.*/i ', $uainfo))
{
Return true;
}
Else
{
Return false;
}
}

/**
* Function Name: ism3gate
* Function Function: Judge whether it is m3gate
* Input Parameters: None
* Function return Value: String returned successfully, failure returned false
* 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 Parameters: None
* Function return Value: String returned successfully, failure returned false
* Other Instructions: description
*/
function Gethttpaccept ()
{
if (Isset ($_server[' http_accept '))
{
Return $_server[' http_accept '];
}
Else
{
Return false;
}
}

/**
* Function Name: GetIP
* Function function: Get phone IP
* Input Parameters: None
* Function return Value: String 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

For WAP development, WAP pages are very simple. It's simpler than HTML. There is no such thing as a table in the wap1.0. All tags are written in a tag called card. Can be used to segment. So it's easy to make a page.

5. Simulator

WAP development is unavoidable to use a variety of simulators to test, better than the M3gate,openwave,opera, there is a call Winwap, we had better not use him to test, his compatibility is too good, Even if the page has errors can be ignored. As you test your Web page with your browser, enter the URL. Nothing is easier than that.

6. Precautions

1) spaces, especially when defining DTDs,


echo "";
?>


If there is less space in the inside, you will be affected. Used to write the page after the rearrangement, put some space to kill, a full search for two geniuses to find the wrong, we must not follow my footsteps.

2) label, if the label is not correct, will prompt the wrong, everyone notice is, it is easy to correct.

  • Related Article

    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.