S
S
Space2015-11-07 11:06:54
PHP
Space, 2015-11-07 11:06:54

How to find the desired element in string?

Get the content of the desired page:

$context = stream_context_create(array("http"=>array(
            "method" => "GET",
           "header" => "Accept: text/*, */*\r\n",
           "ignore_errors" => true,
        )));

       $page = file_get_contents("https://instagram.com/accounts/login/", false, $context);

As I understand it is all a line. I can't figure out how to find the Input and get its value. Tried like this:
$content = preg_match('<input type="hidden" name="csrfmiddlewaretoken" value="(.*?)">', $page, $found);

The value returns empty.
How to get the value of my Input?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Idel Gizatullin, 2015-11-07
@ruslite

It's better not to parse HTML with regular expressions .
It is much more convenient to get the desired input using a CSS selector. Take the appropriate library from TJ or Symfony .

A
Abdula Magomedov, 2015-11-07
@Avarskiy

preg_math() returns 1 or 0 , it does not return what it found... But the name of the variable "$content" for some reason tells me that you are checking it.

Check the $found variable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question