How To Check If A Tag With Specific Title Attribute Is Present In Html By Ganon In Php
This is my code where raw contains an HTML string that has many 'a href' tag with different title attributes, and I want to check if the string has a hyperlink tag with title 'x'.
Solution 1:
You should be able to do the following, not sure exactly what you want to do, but this basically looks for the <a>
with the title attribute which is the one you pass in ($link
) it then outputs the href attribute of this tag. It would be easy to reverse it, but the main thing is the logic of how to find something by the attributes value and then display other parts of the element.
function store($raw, $link)
{
$html = str_get_dom($raw);
$anchor = $html('a[title = "'.$link.'"]');
foreach($anchor as $abc)
{
echo $abc->href."<br>";
}
}
$html = <<< HTML
<html><a href='abc' title='firsttitle'>linkxrefabc</a>
<a href='xref' title='title2'>linkxref</a></html>
HTML;
store($html, 'firsttitle'); // outputs abc<br>
store($html, 'title2'); // outputs xref<br>
Post a Comment for "How To Check If A Tag With Specific Title Attribute Is Present In Html By Ganon In Php"