How to get all the value fields?


There is a script:
function browser($url) {
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_URL,$url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
 $html = curl_exec($ch);
 return $html;
preg_match_all('~<div class="test"-->(.*?)~that is, browser($url), $text);
print_r ($text);

On the page to which the inquiry is going to have a lot of input:
<input type="hidden" name="embed-unikal" class="embed-unikal" value="*****" id="embed-unika">

Please help make the expression for preg_match_all that will get all the value all input. Only fields with a class of embed-unikal.
June 26th 19 at 14:17
2 answers
June 26th 19 at 14:19
If you thought that the regular season is not very convenient to parse the HTML, then hurry to please you - you are not the first person with this opinion.

A long time there are stuff like DOMDocument, SimpleXML or Zend_Dom_Query and dozens of alternatives.

$dom = new Zend_Dom_Query($html);
$results = $dom->query('input .embed-unikal');
June 26th 19 at 14:21
preg_match_all('~<(?:input).*?value="([^"]*)".*?\/>~', browser($url), $text);
and if you want all fields with a class of embed-unikal ? - devin.Huels commented on June 26th 19 at 14:24
please check the necessary lines to complete the match, and if available, use a value - Shakira.Cruickshank commented on June 26th 19 at 14:27

$source = '<input type="hidden" class="embed-unikal" value="one"/--><input type="text" value="two">';

$text = ";

preg_match_all('~<(?:input).*?value="([^"]*)".*?\/>~', $source, $text);

foreach($text[0] as $key => $value)
 if(strpos($value, "embed-unikal") !== false)
 echo $text[1][$key];
- Shakira.Cruickshank commented on June 26th 19 at 14:30

Find more questions by tags Web DevelopmentRegular expressionsPHP