PHP substr loop output
<p>How to loop through  $string text to get all instances at the moment my code only out puts first line  :  fruit apple name stone</p>

<p>How do i make it also check the second line and output :fruit guava name roddy</p>

<p>for example in the $string text below we have :<br>
 foo name stoner and foo name roddy 
 At the moment i can only extract name stoner and script stops.
 I would also like it to extract  name roddy.</p>

<p>sorry if i dont make sense. my english is not that good</p>

<pre><code>$string = 'foo name stoner loller bar php haystack needle fruit apples
foo name roddy koala bar php haystack needle fruit guavas';
$needle = 'fruit';
$needle1 = 'name';
$str = substr($string, strpos($string, $needle) + strlen($needle), 6);
$str1 = substr($string, strpos($string, $needle1) + strlen($needle1), 6);
echo  $needle. $str; 
echo " ";
echo  $needle1. $str1;
</code></pre>