Forum Moderators: coopster
$string = "beginning text string";
everytime the $string is found, i want to copy the next 15 characters into an array
ex:
$string = "hi:";
$text = 'Something hi:copy the next 15 characters. some more text hi:the next 15 chars are very important. and more text. hi:yes copy the next 15 characters.';
$array = functionOfMyDreams($string,$text,$someWierdSyntaxStuff);
i want $array to be
$array[0] = "copy the next 1";
$array[1] = "the next 15 cha";
$array[2] = "yes copy the ne";
i hope this makes sense (i know it seems wierd, but i need it)
i'm pretty sure this requires a Preg function, but i don't know the required syntax
Thanks in advance you all
$string = "hi:";
$text = 'Something hi:copy the next 15 characters. some more text hi:the next 15 chars are very important. and more text. hi:yes copy the next 15 characters.';
$pattern = "/$string(.{15})/Us";
preg_match_all($pattern, $text, $matches);
print_r($matches[1]);
The parentheses capture the string which will be the next 15 of anything after your matched $string.