Problems with PHP for WAP development

Source: Internet
Author: User
Tags format character set header

1. File format
The first problem to be encountered is definitely file format, in the Web development, everyone is using HTML or XHTML, to WAP development, you have to use WML. What is WML? We can go to the more detailed information, I just mention it slightly. In my opinion WML is similar to XML, There is a very strict format, as a WAP page, you have to use WML as a display.

The WML syntax is very simple, and when you use PHP for dynamic output, be sure to send a header message indicating that this page is WML, not something else *ml.


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


Here use the character set is gb2312, on the mobile platform is no problem, but on the platform on the Unicom is not, must be used utf-8, in order to more general, or with utf-8 more secure.


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


2. Code

It says that the character set should adopt Utf-8, which is a character set that accommodates many languages, a Chinese character is a double byte, Utf-8 occupies 4 bytes, so it holds more information. The Chinese characters written on the phone, after converting the page inside code into UTF-8, Later open it may be a bunch of garbled. Therefore, when you make comments, as far as possible in English notes, so as not to understand later. Tools such as Editplus,ultraedit can be transferred to the inner code of the file.

3. Fit and Match

The world's major mobile phone manufacturers are really sick, developed a variety of mobile phones, can be supported by 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 do not fully support it. Although this is the level of the mobile phone and the cost of the open, but it is hard for mobile phone development of the brothers. Because of the inevitable to the mobile phone can support the pictures, ringtones and other multimedia information to make a match, this matching processing, we generally call the phone adapter.
In order to fit the mobile phone, we usually have to have the information.

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

We can make a match with the above stuff. Here's a list of the classes I've written for WAP development, which I can use to get my cell phone number and UA.

 /**
* class Name: Mobile
* Description: Mobile phone Information class
* Other: Accidental writing
*/
Class mobile
{
/**
* Function Name: getphonenumber< br>* function: Take mobile number
* Input parameter: none
* Function return value: Successful return number, failure return FALSE
* Other Description: 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: fetching header information
* Input Parameters: None
* Function return Value: Successful return number, failure return false
* Other Description: 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, failure return false
* Other Description: Description
*/
function Getua ()
{
if (Isset ($_server[' http_user_agent '))
{
Return $_server[' http_user_agent '];
}
Else
{
return false;
}
}

/**
* Function Name: Getphonetype
* Function function: Get the type of mobile phone
* Input Parameters: None
* Function return Value: String returned successfully, failed to return false
* Other Description: Description
*/
function Getphonetype ()
{
$ua = $this->getua ();
if ($ua!=false)
{
$str = Explode (", $ua);
return $str [0];
}
Else
{
return false;
}
}

/**
* Function Name: Isopera
* Function function: To determine whether opera
* Input Parameters: None
* Function return Value: String returned successfully, failed to return false
* Other Description: 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, failed to return false
* Other Description: 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, failed to return false
* Other Description: Description
*/
function Gethttpaccept ()
{
if (Isset ($_server[' http_accept '))
{
Return $_server[' http_accept '];
}
Else
{
return false;
}
}

/**
* Function Name: GetIP
* Function function: Get mobile IP
* Input Parameters: None
* Function return Value: String returned successfully
* Other Description: 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, the WAP page is very simple. It's easier than HTML to be simple. There are no tables or anything in the wap1.0. All the labels are written in a label called Card. So it's easy to make a page.

5. Simulator

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

6. Matters needing attention

1) spaces, especially when defining DTDs,


echo "";
?>


If there is less space in the inside, you will suffer. Used to write when the page after the row, put some space to kill, a full find two geniuses to find the wrong, we must not step in my footsteps.

2 label, if the label is not right, will prompt error, everyone attention is, it is easy to amend.



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.