PHP Scripting Forums » General Web Development Forum

Parsing the user_agent from cell phones

(22 posts)
Great offers not only for geeks!
Your Ad Here

  1. User has not uploaded an avatar

    hmvrulz
    Member

    $data = file_get_contents("http://www.finalwebsites.com");
    $pattern = "/src=[\"β€˜]?([^\"’]?.*(png|jpg|gif))[\"’]?/i";
    preg_match_all($pattern, $data, $images);

    here for the $pattern
    how can i get the info bw

    user_agent=” info ”
    i want to extract the β€œinfo”
    part from a file

    can u tell me how to add tht to the $ pattern

    the file is a xml file...

    Posted 9 months ago #
  2. If you have an xml file you should use some xml parser (DOM, SAX), there are plenty of them.

    Please tell me more about the "agent" thing, what do you want to do exaxtly?

    Posted 9 months ago #
  3. User has not uploaded an avatar

    hmvrulz
    Member

    Quote from: Olaf
    "If you have an xml file you should use some xml parser (DOM, SAX), there are plenty of them.
    Please tell me more about the "agent" thing, what do you want to do exaxtly?"

    i am using some opensource xml which contains info about mobile phone models and its compatiblity... but tht file is too huge compared to wht i want..
    i just wanna create a module where when i mobile device visits a page it HTTP_agent is taken n compared with the database to get back the model

    this info is there in the xml file... so i wanna extract the info
    user_agent=” info ”

    here info is the mobile device tht returns USER AGENT data

    Posted 9 months ago #
  4. I guess you need this script.

    Posted 9 months ago #
  5. User has not uploaded an avatar

    hmvrulz
    Member

    i have been thru tht script before... it contains old data.. new mobile data is not there...
    the xml file i have contains latest info and they keep upgrading on very handset release
    http://wurfl.sourceforge.net/

    have a look at it there..
    if u can help me use tht itself i wil be more great ful.. but i don under wht he says.. i am still a newbie...

    it literally goes over my head..
    so i though let me extract all the info n make my own db which wil take time but worth i feel...

    Posted 9 months ago #
  6. You should start with this example:

    http://wurfl.sourceforge.net/php/index.php

    look the problem is that you need to know all strings to include them in your pattern.

    Still sure the best way is parsing the XML, how big is the file?

    Posted 9 months ago #
  7. User has not uploaded an avatar

    hmvrulz
    Member

    Quote from: Olaf
    "You should start with this example:
    http://wurfl.sourceforge.net/php/index.php
    look the problem is that you need to know all strings to include them in your pattern.
    Still sure the best way is parsing the XML, how big is the file?"

    it more than 6 mb...can u tell me how to extract only few fields

    like user_agent and model ??

    Posted 9 months ago #
  8. The parser on that page is a SAX parser which is an event based parser, perfect for bigger files

    but OK, please post some "complete" headers you want to parse (at least 2 or 3 different models)

    Posted 9 months ago #
  9. User has not uploaded an avatar

    hmvrulz
    Member

    <device id="nokia_n95_ver1_sub100014" user_agent="Mozilla/5.0 (Symbianos/9.2; U; Series60/3.1 NokiaN95/10.0.014; Profile/MIDP-2.0 Configuration/CLDC-1.1) AppleWebKit/413 (KHTML, like Gecko) Safari/413" fall_back="nokia_n95_ver1">
        <group id="product_info">
          <capability name="has_pointing_device" value="true"/>
        </group>
        <group id="xhtml_ui">
          <capability name="xhtml_display_accesskey" value="false"/>
          <capability name="xhtml_format_as_attribute" value="false"/>
        </group>
        <group id="bearer">
          <capability name="max_data_rate" value="1800"/>
          <capability name="wifi" value="true"/>
        </group>
      </device>

    <device id="nokia_n73_ver1_sub40727221" user_agent="NokiaN73-1/4.0727.2.2.1 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1" fall_back="nokia_n73_ver1"/>

    the problem is not all devices have same variables its really complicated for me...

    Posted 9 months ago #
  10. User has not uploaded an avatar

    hmvrulz
    Member

    else u can help me with just extracting the
    user_agent="Mozilla/5.0 (Symbianos/9.2; U; Series60/3.1 NokiaN95/10.0.014; Profile/MIDP-2.0 Configuration/CLDC-1.1) AppleWebKit/413 (KHTML, like Gecko) Safari/413"

    and
    user_agent="NokiaN73-1/4.0727.2.2.1 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1"

    from the above example

    its enuf

    Posted 9 months ago #

RSS feed for this topic

Reply »

You must log in to post.