dyluck Posted May 23, 2010 Share Posted May 23, 2010 HI there, Has anyone the answer to this question? Lets say I have a big string $string = "The quick brown fox jumps over the moon to discover that it really wasn't the moon at all but a big rock in the ground"; $delimiter = "discover"; $maxlenth = 15; I want to limit the charaters before and after the delimiter by 15 charaters (as an example). DESIRED RESULT: "er the moon to discover that it really" Thanks for your help! Quote Link to comment Share on other sites More sharing options...
-Karl- Posted May 23, 2010 Share Posted May 23, 2010 strpos() perhaps? Quote Link to comment Share on other sites More sharing options...
ldb358 Posted May 23, 2010 Share Posted May 23, 2010 you could do something like this: <?php $string = "The quick brown fox jumps over the moon to discover that it really wasn't the moon at all but a big rock in the ground"; $delimiter = "discover"; $maxlenth = 15; $new = substr($string,strpos($string,$delimiter)-$maxlenth,$maxlenth*2+strlen($delimiter)); ?> Quote Link to comment Share on other sites More sharing options...
dyluck Posted May 23, 2010 Author Share Posted May 23, 2010 you could do something like this: <?php $string = "The quick brown fox jumps over the moon to discover that it really wasn't the moon at all but a big rock in the ground"; $delimiter = "discover"; $maxlenth = 15; $new = substr($string,strpos($string,$delimiter)-$maxlenth,$maxlenth*2+strlen($delimiter)); ?> Works like a charm! thank you so much!!!! This helped a lot and coudln't seem to get my head around it lol! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.