0
Hello,
I have the following function:
function capturar($string, $start, $end) {
$str = explode($start, $string);
$str = explode($end, $str[1]);
return $str[0];
}
I use it with Curl, to get the value of an input.
Example of use:
$pagina = curl("http://example.com");
$texto = capturar($pagina, 'name="texto"', '"');
echo $texto;
Then in the case, PHP would return the input value or any tag that has the name of texto, so far so good, but the page that Curl accesses has the following input:
<input value="João Lima" name="texto" id="texto"/>
How would I get the value of the input in this order?
Thanks in advance.
Current code I’m using:
<?php
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd().'/test.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd().'/test.txt');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$array = [];
preg_match('/value="([^"]+)"/e', curl('http://example.com'), $array);
var_dump($array);
echo '<br><br><br><br>'.curl('http://example.com');
This page has other inputs, but has an input with the value of 11.5, 12, 12.5.
And when the
valuecontain numbers? I put an input withvalueof11.5, 12, 12.5and did not return thevaluein the array.– STRILEXLIVE
You are sure, because I tested with these values and it worked. Ta doing so: value="11.5" ?
– mau humor
Yes, I tested with these values only in the string, then I went to test with Curl, but it does not return.
– STRILEXLIVE