doa24uk Posted March 16, 2010 Share Posted March 16, 2010 Hey guys, Lets say this is a portion of my HTML output page <ul> <li>Listing One</li> <li>Listing Two</li> <li>Listing Three</li> </ul> Here's my psuedo code for what I want to do. $text to find = "Listing Three"; if $text to find = found { echo Found in position 3. } else Sorry, text not found I do have a Javascript script that will number the results ... javascript:var%20p=document.getElementsByTagName('li');var%20j=1;function%20gc(){for(i=0;i<p.length;i++){if(p[i].className=='g'){p[i].innerHTML=j+'.%20'+p[i].innerHTML;j++;}};};gc(); But I've got no idea if I have to pre-number the results in PHP or if PHP can just find it straight off..... Quote Link to comment https://forums.phpfreaks.com/topic/195447-get-number-of-on-page-output-result/ Share on other sites More sharing options...
Maq Posted March 16, 2010 Share Posted March 16, 2010 You can use the DOM or SimpleXML libraries, along with a bit of XPath to accomplish this. Quote Link to comment https://forums.phpfreaks.com/topic/195447-get-number-of-on-page-output-result/#findComment-1027041 Share on other sites More sharing options...
nafetski Posted March 16, 2010 Share Posted March 16, 2010 Well, this is a tricky question. First - your best bet is using javascript...use jQuery (www.jquery.com) and learn the basics of the framework. You will be able to solve this problem in 30 min tops. Now, if you are echoing out these <li> in PHP (say in a loop) then you can just count the number of times you are looping. If this is an HTML file, and you want PHP to do some processing...then you'd have to load the HTML file into PHP, then run some regex to pull those results. Trust me tho, for what you want to do it sounds like javascript is giong to be your best option...and jquery is the golden ticket. Let me know if you have any questions. (The jquery code for what you'd want to do) $("li").each(function(){ if ($(this).text == "Listing Three) { alert('listing three is on page'); } }); Quote Link to comment https://forums.phpfreaks.com/topic/195447-get-number-of-on-page-output-result/#findComment-1027046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.