Måske denne er pænere:
<?php
//http://www.eksperten.dk/spm/765172
function strposnth($haystack, $needle, $nth=1, $insenstive=0)
{
//if its case insenstive, convert strings into lower case
if($insenstive)
{
$haystack=strtolower($haystack);
$needle=strtolower($needle);
}
//count number of occurances
$count=substr_count($haystack,$needle);
//first check if the needle exists in the haystack, return false if it does not
//also check if asked nth is within the count, return false if it doesnt
if ($count<1 || $nth > $count)
return false;
//run a loop to nth number of accurance
//start $pos from -1, cause we are adding 1 into it while searchig
//so the very first iteration will be 0
for($i=0,$pos=0,$len=0;$i<$nth;$i++)
{
//get the position of needle in haystack
//provide starting point 0 for first time ($pos=0, $len=0)
//provide starting point as position + length of needle for next time
$pos=strpos($haystack,$needle,$pos+$len);
//check the length of needle to specify in strpos
//do this only first time
if ($i==0)
$len=strlen($needle);
}
//return the number
return $pos;
}
$besked = 'SOLRØD BC BESKED HER';
$space = ' ';
echo substr($besked,strposnth($besked, $space, 2));
?>
Den er fundet på
http://www.php.net/strpos -> webKami [at] akdomains.com