swraman Posted May 11, 2013 Share Posted May 11, 2013 Hi, Im working on a project where I have to sift through the entire HTML code of a webpage, and extract everything that lies within a certain HTML tag. Essentially, at least as I see it, I need to sort through the entire webpage html source and find all occurrences of a certain html tag. What would be the best way to do this? I want to be sure to do it efficiently as I will be searching through ~2500 lines of html for each time the script is called. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/277912-best-way-to-search-through-long-strings/ Share on other sites More sharing options...
swraman Posted May 11, 2013 Author Share Posted May 11, 2013 by the way I am currently using strstr to find the first occurence of the tag, and calling strstr until it returns false. Quote Link to comment https://forums.phpfreaks.com/topic/277912-best-way-to-search-through-long-strings/#findComment-1429643 Share on other sites More sharing options...
jcbones Posted May 11, 2013 Share Posted May 11, 2013 preg_match_all OR DomDocument class OR SimpleHTMLDom class I've used all three, and would suggest the 1st and 3rd. In my experience the 2nd doesn't always like HTML. Quote Link to comment https://forums.phpfreaks.com/topic/277912-best-way-to-search-through-long-strings/#findComment-1429644 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.