Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery's $ function for PHP

I'm wondering that if there's something like JQuery's $('element.selector') implemented for PHP?

When I CURL and I got HTML codes from the remote site, I'd like to select only the tags I want before I send out to my HTML.

Thanks

like image 963
Moe Sweet Avatar asked Dec 01 '22 10:12

Moe Sweet


1 Answers

The PHP Simple HTML DOM Parser has a similar functionality:

// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

// Find all images 
foreach($html->find('img') as $element) 
       echo $element->src . '<br>';

// Find all links 
foreach($html->find('a') as $element) 
       echo $element->href . '<br>';
like image 102
Gumbo Avatar answered Dec 05 '22 12:12

Gumbo