Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

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.

Dream-mobile.co.cc is an example website using this class.

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

Back to method list

Method nameget_param_list()
DescriptionReturns array with all parameters by which mobile phones can be searched

Get all values for specified parameter

Back to method list

Method nameget_all_values($param_name)
DescriptionReturns array with all possible values for specified parameter

Construct request url

Back to method list

Method namemake_url($arr, $ex = array())
DescriptionGenerates 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 inputmake_url(array("camera_resolution" => 3))
Example outputhttp://phonescomplete.com/phones/search.xml?camera_resolution=3

Get all information about phone

Back to method list

Method nameget_phone($cached_slug, $xml = false)
DescriptionGets 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 inputget_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

Back to method list

Method namefrom_to($arr, $param_name)
DescriptionGenerate 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 inputfrom_to(array(1,5), "camera_resolution")
Example output&camera_resolution[]=1&camera_resolution[]=3&camera_resolution[]=4&camera_resolution[]=5

Perform search

Back to method list

Method namesearch($url, $xml = false)
DescriptionPerform 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 inputsearch("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

blog comments powered by Disqus