Phones Complete class
Phones Complete class can be used to query information of mobile devices from Phones Complete database.
It can send HTTP requests to the PhonesComplete Web services API to retrieve information for a given mobile phone.
The class parses the response and returns the mobile device information in an array or the raw XML response.
It also provides ability to create user friendly interfaces for searching through Phones Complete database.
Contents
Download
Example codes
<?php //declaring class instance include("./mobile.class.php"); $mob = new mobile_phones(); if(isset($_POST['search'])) { //excluding post search data from request url $ex[0] = 'search'; //creating search url from array of parameters $url = $mob->make_url($_POST, $ex); //performing search based on created url $phones = $mob->search($url); //outputing result echo "<pre>"; print_r($phones); echo "</pre>"; } //selecting all phone related parameters $arr = $mob->get_param_list("bluetooth"); //simple userinterface form echo "<form action='' method='post'>"; echo "<table>"; foreach($arr as $key => $val) { echo "<tr>"; //create select input for bluetooth if($val == "bluetooth") { echo "<td>".$val."</td><td><select name='".$val."'>"; echo "<option value=''></option>"; //selecting all possible values for bluetooth parameter $btvals= $mob->get_all_values($val); //outputting values foreach($btvals as $bt) { echo "<option value='".$bt."'>".$bt."</option>"; } echo "</select></td>"; } //else creating simple text boxes else { echo "<td>".$val."</td><td><input type='text' name='".$val."' "; if(isset($_POST[$val])) { echo "value='".$_POST[$val]."'"; } echo "/></td>"; } echo "</tr>"; } echo "<tr><td colspan='2' align='center'><input type='submit'"; echo " value='Search'/></td></tr>"; echo "</table>"; echo "<input type='hidden' name='search'/>"; echo "</form>"; ?>
Examples in action
Example scripts provided with package in action:
Method list
- Get all parameters
- Get all values for specified parameter
- Construct request url
- Get all information about phone
- Get value from to interval
- Perform search
Get all parameters
| Method name | get_param_list() |
| Description | Returns array with all parameters by which mobile phones can be searched |
Get all values for specified parameter
| Method name | get_all_values($param_name) |
| Description | Returns array with all possible values for specified parameter |
Construct request url
| Method name | make_url($arr, $ex = array()) |
| Description | Generates url to which make search request with all provided search parameters. if $arr array element is another array, then from_to method is aplied |
| Input parameters | array $arr - array with parameter names as key and searchable values as values array $ex - array with paramater names as values, which to exclude from url |
| Example input | make_url(array("camera_resolution" => 3)) |
| Example output | http://phonescomplete.com/phones/search.xml?camera_resolution=3 |
Get all information about phone
| Method name | get_phone($cached_slug, $xml = false) |
| Description | Gets information about phone based on provided cached_slug parameter value |
| Input parameters | string $cached_slug - unique phone identifier of phones complete database boolean $xml - if $xml is true, information about phone is provided in xml format, else informations provided in array, where parameter names are the keys and values are values of array |
| Example input | get_phone("galaxy-551", true) |
| Example output | <phone> <a2dp type="boolean"> true </a2dp> <age type="date"> 2010-11-01 </age> <bluetooth/> <brand> Samsung </brand> <cached-slug> galaxy-551 </cached-slug> <camera-flash/> <camera-resolution type="integer"> 3 </camera-resolution> ... </phone> |
Get value from to interval
| Method name | from_to($arr, $param_name) |
| Description | Generate part of url with interval of values to satisfy condition like camera_resolution > 1 && camera_resolution < 5 |
| Input parameters | array $arr - first element is minimal value, second parameter - maximum value string $param_name - parameter name, for which to generate interval url part |
| Example input | from_to(array(1,5), "camera_resolution") |
| Example output | &camera_resolution[]=1&camera_resolution[]=3&camera_resolution[]=4&camera_resolution[]=5 |
Perform search
| Method name | search($url, $xml = false) |
| Description | Perform search with url from method make_url |
| Input parameters | string $url - URL generated by make_url method boolean $xml - if $xml is true, information about phone is provided in xml format, else informations provided in array, where parameter names are the keys and values are values of array |
| Example input | search("http://phonescomplete.com/phones/search.xml?camera_resolution=3", true) |
| Example output | <phones type="array"> <phone> <a2dp type="boolean"> true </a2dp> <age type="date"> 2009-10-01 </age> <bluetooth> 2.1 </bluetooth> <brand> Nokia </brand> <cached-slug> x3 </cached-slug> |
Latest changes
None for now
You may also be interested in:
Powered by BlogAlike.com










