freshwebs Posted July 29, 2006 Share Posted July 29, 2006 I need some help creating a function that will be passed a block of html, a search tag, and the instance. It will find the end of that specific tag and return everything between its opening and closing tags.For example:[code]function get_tag_contents($haystack, $tag, $instance=0) { // function code}[/code]It would work like this:[code]$html = "<div id="page"><div>text a</div><div>text b</div>text c<div><div>text d</div></div></div>";get_tag_contents($html, "<div>");// would return "<div>fasdfsadf</div><div>hjkh</div>asdfas<div><div>dfasdf</div></div>"get_tag_contents($html, "<div>", 1);// would return "text a"get_tag_contents($html, "<div>", 3);//would return "<div>text d</div>"[/code]Can anyone help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/15958-parse-single-html-tag/ Share on other sites More sharing options...
freshwebs Posted August 6, 2006 Author Share Posted August 6, 2006 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/15958-parse-single-html-tag/#findComment-70293 Share on other sites More sharing options...
xec Posted August 6, 2006 Share Posted August 6, 2006 please redefine your query, i cant understand want to get from the e.g you have provided... Quote Link to comment https://forums.phpfreaks.com/topic/15958-parse-single-html-tag/#findComment-70295 Share on other sites More sharing options...
ignace Posted August 6, 2006 Share Posted August 6, 2006 the ereg family can do this trick for you, but parsing html, into objects is quite hard, especially with all the attributes and everything, if you have php 5, xml should be supported try looking into that code, maybe copy, past some of it, to get the function you are planning to use Quote Link to comment https://forums.phpfreaks.com/topic/15958-parse-single-html-tag/#findComment-70297 Share on other sites More sharing options...
freshwebs Posted August 6, 2006 Author Share Posted August 6, 2006 Yeah, I've thought about using the XML extensions but I don't have PHP5 installed on the server I use. Quote Link to comment https://forums.phpfreaks.com/topic/15958-parse-single-html-tag/#findComment-70299 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.