Your Regex is different from your html-input, just compare:
<input value="2530317385" name="X-Tmx-session-id" id="X-Tmx-session-id" type="hidden">
~<input type=hidden id=X-Tmx-session-id name=X-Tmx-session-id value=(.*?) \/>~
Missing quotes, position requested by Regex is different.
If you are getting an html by curl
, why not use the DOM to pick up the elements? For example:
$get = '<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input value="test1">
<input value="test2">
<input value="test3">
</body>
</html>';
$doc = new DOMDocument();
@$doc->loadHTML($get); //O @ previne mostrar erro de HTML
$allInputs = $doc->getElementsByTagName('input');
foreach ($allInputs as $input) {
echo $input->getAttribute('value'), '<br>';
}
Or with Xpath (chance needs more advanced selectors):
<?php
$get = '<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input value="2530317381" name="X-Tmx-session-id" id="X-Tmx-session-id" type="hidden">
<input value="2530317382" name="X-Tmx-session-id" id="X-Tmx-session-id" type="hidden">
<input value="2530317383" name="X-Tmx-session-id" id="X-Tmx-session-id" type="hidden">
<input value="2530317384" name="X-Tmx-session-id" id="X-Tmx-session-id" type="hidden">
</body>
</html>';
$doc = new DOMDocument();
@$doc->loadHTML($get);
$xpath = new DOMXpath($doc);
$doc = NULL;
$allInputs = $xpath->query('*/input[@id=\'X-Tmx-session-id\']');
foreach ($allInputs as $input) {
echo $input->getAttribute('value'), '<br>';
}
Online example: https://ideone.com/i9ZCsg
You just return the
value
of that input?$_GET/$_POST
doesn’t solve this?– rray
The $get variable takes the html that comes from the Curl
– Lucas Casterlamar
@Lucascasterlamar your last Dit deformed the question. I restored the question. If you want you can delete the question or ask one of the moderators for help to delete it. If you have any questions, please comment here or at the goal (http://meta.pt.stackoverflow.com/) that we will assist you.
– Sergio
@Sergio I did not understand why he copied the answer code and put the question, I think he did not understand how Stackoverflow works. Rollback to Revision 3. Lucas is a community of questions and answers, if the answer code didn’t work you can comment by speaking the problem in the answer itself.
– Guilherme Nascimento