0

I want to see all field input and textarea but I don't know how to show it together in the same code. and in case I want to skip something for example I want to write directly input name without make him check the type or I don't want him to show me the readonly so how can I do it ?

  <form method="post" action="" id="submit_form">

  <input type="text" name="TITLE" value="" size="40" maxlength="100" class="text" />

  <textarea name="DESCRIPTION" rows="4" cols="36" class="textarea"></textarea>

  <input type="text" name="DESCRIPTION_limit" size="4" class="limit_field" readonly="readonly" value="250" />

  <textarea name="ARTICLE" id="ARTICLE" rows="6" cols="50" class="textarea"></textarea>

  <input type="text" name="META_KEYWORDS" value="" size="40" maxlength="2000" class="text" /> 
preg_match_all('/<(input)[\s](type)="?([^>"]*)"?[\s](name)="?([^>"]*)"?[\s]/', file_get_contents($url), $matches);
echo"<pre>";
print_r($matches);

lolo
  • 11
  • 7
  • 4
    [Don't use regex to parse HTML](https://stackoverflow.com/a/1732454/2453432). Use [DOMDocument](https://www.php.net/manual/en/class.domdocument.php) or similar instead. – M. Eriksson May 22 '19 at 13:39
  • Possible duplicate of [RegEx match open tags except XHTML self-contained tags](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – kafman May 22 '19 at 15:13
  • @MagnusEriksson i know but i have to do it with regex – lolo May 23 '19 at 06:39
  • May I ask why you _"have to do it with regex"_? It's simply the wrong tool for the job. It's like telling a carpenter that they must use a wrench for hammering in nails. With some extra work, you might get it working, but it's still a bad choice. – M. Eriksson May 23 '19 at 08:17

1 Answers1

1

I tested this code with the line "$string". Type and Name attributes can be in any order in the input tag, and it searches until it reads a ">" character.

    $string = '<input type="text" name="TITLE" value="" size="40" maxlength="100" class="text" />';
    preg_match_all('/<input[^>]*?(?:(type)="([^"]*)")|(?:(name)="([^"]*)")/', $string, $matches);
    if($matches[1][0] == "type" && $matches[3][1] == "name"){
    $type = $matches[2][0];
    $name = $matches[4][1];
    }
    elseif($matches[1][0] == "name" && $matches[3][1] == "type"){
    $name = $matches[2][0];
    $type = $matches[4][1];
    }
    else{
        throw new Exception('no input tags with type and name attributes were found!');
    }
    echo $type;
    echo $name;
blackdrumb
  • 310
  • 1
  • 8
  • this code doesn't work.... i don't want to do it like this for example iwant to look for every code have name or input name but i need him to ignore the type because in preg_match he start match in the order step by step – lolo May 23 '19 at 07:37