Forum Moderators: coopster
I require little help with PHP regex.
I've a whole dump of text:
I wanna count occurence of _L_ in it. I did it easily.
_L_ is 100 times in it.
I wanna get occurence of 'www.example.com' in dump text, if found, stop and return counted value of _L_ like 23rd _L_ or 59th _L_ or 95th _L_
How can this be done using PHP and regex?
There may be more than one occurence of 'www.example.com'
function countLs($subject)
{
$pattern = '/(_L_¦www\.example\.com)/'; // retype the pipe!
$found = preg_match($pattern, $subject, $matches);if (!$found)
{
return 0;
}$size = count($matches);
$count = 0;
$continue = true;
while ($count < $size && $continue)
{
if ($matches[$count] == 'www.example.com')
{
$continue = false;
}
else
{
$count++;
}
}return $count;
}