Counting <LI> elements from another page
I have two pages, page A and page B. Page A will contain an unknown number of unordered list items. I will not control how many elements of the list are.
On page B, I would like to use PHP to capture the number li from page A and display that number. The idea is that page A will contain the Wordpress links that the user prefers, and page B displays that number of favorites.
Any help would be wonderful. Thanks
+4
1 answer
Parse html from another page using PHP Simple HTML DOM Parser . Download it and include it in your script:
include('simple_html_dom.php'); $html = file_get_html('http://example.com/yourpage.php'); $licount = count($html->find('li')); // Here it is Good. It looks like OP does not need to use server-side code. Use javascript for this (don't forget to enable jQuery):
$(document).ready(function(){ $.get("/favorites", function(data){ $("#favorites").html($("li", $(data)).length) }) }) This will replace the contents of the #favorites element #favorites number li in the file / favorites
+2