SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_match_all pattern help

    This is the html page which is stored in $content variable. (Its only a snippet of the overall html page)
    Code:
    <input name=".intl" value="us" type="hidden">
      	<input name=".bypass" value="" type="hidden">
      	<input name=".partner" value="" type="hidden">
      	<input name=".u" value="44q6bst25a559" type="hidden">
              <input name=".v" value="0" type="hidden">
    The following is the code I'm using. I want it to put all the value of attributes, i.e. for this example, value of name and value attributes to $matches array. The above input html contents plus other contents are stored in $content variable.
    Code:
    preg_match_all('/<input name="([^"]*)" value="([^"]*)" type="hidden" >/', $content, $matches);
    And when I do the var_dump($matches), its empty.
    Could you please suggest me a way out how to alter the pattern to get the desired result for me.

    Thanks in advance.

  2. #2
    Non-Member Gator99's Avatar
    Join Date
    Sep 2004
    Location
    Florida
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This will give you an array with the field's names and values.
    Code:
    //get rid of line breaks
    $content=preg_replace("/\r*\n/","",$content);
    $matches=array();
    preg_replace('/<input name="(.*)" value="(.*)" type="hidden">/e', "\$matches['\\1']='\\2';",$content);

  3. #3
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by millisami
    Code:
    preg_match_all('/<input name="([^"]*)" value="([^"]*)" type="hidden" >/', $content, $matches);
    I imagine you regex is only failing because of the space you have after type="hidden"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •