开发者

JQuery's $ function for PHP

开发者 https://www.devze.com 2023-01-13 21:18 出处:网络
I\'m wondering that if there\'s something like JQuery\'s $(\'element.selector\') implemented 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


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>';


Or perhaps Querypath (http://querypath.org/)? Just read about it yesterday and it looks kind of cool.


$ctx = xpath_new_context($doc); 
$xpath_nodes = xpath_eval($ctx, "//some_element"); 


You could use server-side javascript. Haven't done that myself yet, though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号