1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Regular expression

Discussion in 'PHP' started by ssimon171078, Feb 18, 2016.

  1. #1
    i have html code i need to receive name +price how can i build Regular expression with php:
    <a href="/p/doogee-titans2-dg700-android-4-4-quad-core-wcdma-bar-phone-w-4-5-ogs-8gb-rom-gps-otg-presale-852367526" title="DOOGEE TITANS2 DG700 Android 5.0 Quad-Core WCDMA Bar Phone w/ 4.5&quot; OGS, 8GB ROM, GPS, OTG">DOOGEE TITANS2 DG700 Android 5.0 Quad-Core WCDMA Bar Phone w/ 4.5" OGS, 8GB ROM, GPS, OTG</a>
    HTML:

    <p class="price">
                    US$103.46
                </p>
    HTML:
    how can i use preg_match_all() ?
     
    ssimon171078, Feb 18, 2016 IP
  2. RapidVideo

    RapidVideo Greenhorn

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    scan for lines

    apply for example:

    if(preg_match("/\/p\//i", $line)) {

    and also

    if(preg_match("/class=\"price\"/i", $line)) {

    then you can use explode() to get the content of a href or the content inside <p>
     
    RapidVideo, Feb 18, 2016 IP
  3. otakatun

    otakatun Well-Known Member

    Messages:
    388
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    108
    #3
    For scraping HTML code, it is wise to not use regex as the HTML is more complex than that.

    You could use DOM or XPATH for this
     
    otakatun, Feb 19, 2016 IP
  4. Eager2Seo

    Eager2Seo Member

    Messages:
    72
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #4
    Malformed HTML don't always work with XPATH. This is a great library.
    I've never seen in break and ran some nasty crap thru it.
    http://simplehtmldom.sourceforge.net/
     
    Eager2Seo, Mar 1, 2016 IP