Need help with regex

Discussion in 'PHP' started by rajesh_, Aug 3, 2009.

  1. #1
    I have string as show below.

      <input type="hidden" name="dsh" id="dsh"
               value="4965535939321092909" />
    
    HTML:
    $string = '<input type="hidden" name="dsh" id="dsh"
               value="4965535939321092909" />';
    PHP:
    you can see value is in second line.


    I need to extract value field using regex. Any help would be appreciated.
     
    rajesh_, Aug 3, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    preg_match_all('/<input.*value="([^"]+)"/Umsi', $string, $matches, PREG_SET_ORDER);
    PHP:
     
    premiumscripts, Aug 3, 2009 IP
  3. rajesh_

    rajesh_ Active Member

    Messages:
    172
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3

    Thanks for reply.. i need id also. BEcause page got many inputs.
     
    rajesh_, Aug 3, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    preg_match_all('/<input.*(?:id="([^"]+)").*value="([^"]+)"/Umsi', $string, $matches, PREG_SET_ORDER);
    PHP:
     
    premiumscripts, Aug 3, 2009 IP