I'm trying to find a way to get the content of this HTML attribute "name", using PHP getStr, I can't get it to work anyhow, I have already searched, but I couldn't find find something that may help me.
<input id="9d6e793e-eed2-4095-860a-41ca7f89396b.subject" maxlength="50" name="9d6e793e-eed2-4095-860a-41ca7f89396b:subject" value="" tabindex="1" class="subject required field" type="text"/>
I want to get this value into a string:
9d6e793e-eed2-4095-860a-41ca7f89396b:subject
I can get the value of a tag like this one:
<input type="hidden" name="message" value="1442814179635.Oz1LxjnxVCMMJ0QpV0wGLx4roEA="/>
With this code:
getStr($b,'name="message" value="','"');
But I can't find a way to get the attribute name of the first one?
Use regular expressions in PHP. This code should be helpful:
<?php
$str = '<input type="hidden" name="message" value="1442814179635.Oz1LxjnxVCMMJ0QpV0wGLx4roEA="/>';
//forward slashes are the start and end delimeters
//third parameter is the array we want to fill with matches
if (preg_match('/name="([^"]+)"/', $str, $m)) {
print $m[1];
} else {
//preg_match returns the number of matches found,
//so if here didn't match pattern
}
Output:
message
Check the PHP DOMElement::getAttribute method. It's all in the manual
Here you go:
<?php
$html = '<input id="9d6e793e-eed2-4095-860a-41ca7f89396b.subject" maxlength="50" name="9d6e793e-eed2-4095-860a-41ca7f89396b:subject" value="" tabindex="1" class="subject required field" type="text"/>';
$doc = new DOMDocument;
$doc->loadHTML($html);
$elements = $doc->getElementsByTagName("input");
foreach($elements as $element){
echo $element->getAttribute('name');
}
?>
This bit of code will do what you want:
<?php
$b = '<input id="9d6e793e-eed2-4095-860a-41ca7f89396b.subject" maxlength="50" name="9d6e793e-eed2-4095-860a-41ca7f89396b:subject" value="" tabindex="1" class="subject required field" type="text"/>';
echo "\$b = $b
";
$rest = substr(strstr($b,'name="'),6);
echo "\$rest = $rest
";
$name = strstr($rest,'"',true);
echo "\$name = $name
";
?>