How to get all occurences of string in string?
Posted: Mon Dec 06, 2004 7:06 pm
I am using this function to get a part of the html code from a web page, between the specified start & end tags. It works just fine. But it returns only the first occurence of the result string.
How should I alter the code to alter all occurences of the string between multiple start & end tags? To clarify - there can be something like this in the source html:
<!--Start_Tag-->
Some content
<!--End_Tag-->
<!--Start_Tag-->
Some different content
<!--End_Tag-->
Right now it returns only "Some content" but I'd like it to return both "Some content" & "Some different content" as one result string.
As always, any suggestions are welcome!
Tomas
Code: Select all
function get_page_html($pagename, $start_tag, $end_tag){
$page_content = file_get_contents($pagename);
$from = strpos($page_content, $start_tag);
$to = strpos($page_content, $end_tag);
$page_part = substr($page_content, $from, $to - $from);
return $page_part;
}<!--Start_Tag-->
Some content
<!--End_Tag-->
<!--Start_Tag-->
Some different content
<!--End_Tag-->
Right now it returns only "Some content" but I'd like it to return both "Some content" & "Some different content" as one result string.
As always, any suggestions are welcome!
Tomas