So I have this script that extracts a given string within a bigger string:
function get_string($string, $start, $end){
$string = " ".$string;
$pos = strpos($string,$start);
if ($pos == 0) return "";
$pos += strlen($start);
$len = strpos($string,$end,$pos) - $pos;
return substr($string,$pos,$len);
}
So this is the string:
$string= '<b>Sample Sample</b> <b>Sample2 Sample2</b>';
$output = get_string($string, '<b>','</b>');
echo $output;
I really want some help on this because I’m out of ideas. Now when i echo $output I get
Sample Sample
I want to make a change that would display both:
Sample Sample
Sample2 Sample2
Does any of you guys have any ideas how to modify the function and make it output sort
of an array of results $output[0], $output[1]?
Thank you in advance,
Wish you a good day.
Modify your function so that as long as
while, that function gives you a string, add it to an array, and run the function again with the end of the string.EDIT:
Didn’t want to spell out a correct solution if you happened to want to try it your self. Here’s one way to do it, resulting in what you want. I tried to make as few changes to your original post as possible:
outputs: