1

In PHP I'm using the Simple HTML DOM Parser class.

I have a HTML file which has multiple and diferents tags.

In this HTML there is an element like this:

<a name="10418"><b>&nbsp;Hospitalist (Family Practitioner)</b></a>

So I would like to find that 'a' element with has name="10418"

I've tried this with no luck, because I only want to get that string.

  $html_object = str_get_html($url);
  $html_object=$html_object->find('a');
  foreach ($html_object as $o) {
            $a= $o->find("b");
            echo $a[0];
 }

2 Answers 2

3

Try:

$anchor = $html_object->find('a[name=10418]', 0);
echo $anchor->plaintext;

Working DEMO

Sign up to request clarification or add additional context in comments.

3 Comments

that gives me this error: Notice: Trying to get property of non-object
@user3002293, it works fine, check the demo... Are you sure your html code contains that anchor ? (give me the link to check if possible)
could you try this please? pastebin.com/qJXQbvyh I don't know why my code is getting that error
0

Try another library called Tag Parse.It's simple and efficient.

$dom = new TagParse\TagDomRoot($html);
$a = $dom->find('a[name="10418"]');

I think it's fast and cost less memory than simple_html_dom.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.