Search code examples
phpsimple-html-dom

How to get desire innertext from html tag in simple html dom


I have some text in which there is codes. I want to get last text from the link. here is an example

Some text<a href="http://beezfeed.cu.ma">Beezfeed.cu.ma</a><br>
another text<a href="http://google.com">Google.com</a><br>

I want to get Google.com text from the above code. I have tried and use Simple html dom. Anyway Here is my code

   <?PHP
require_once('simple_html_dom.php');
$html = new simple_html_dom();
function tags($ddd){
$bbb=$ddd->find('a',1);
    foreach($bbb as $bs){
    echo $bs->innertext;
    }
}
$html = str_get_html('Some text<a href="http://beezfeed.cu.ma">Beezfeed.cu.ma</a><br>
another text<a href="http://google.com">Google.com</a><br>');

echo tags($html);
?> 

I want to get Google.com how to get. Please help me


Solution

  • I strongly recommend you use some external library to parse HTML. Any HTML you need. As you need today or in future needs. Some very good tools are named inside these stackoverflow post.

    I personally use simplehtmldom.sourceforge.net since ages with very good results.