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! Link to comment https://forums.phpfreaks.com/topic/202658-manipulating-a-string/ Share on other sites More sharing options...
-Karl- Posted May 23, 2010 Share Posted May 23, 2010 strpos() perhaps? Link to comment https://forums.phpfreaks.com/topic/202658-manipulating-a-string/#findComment-1062266 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)); ?> Link to comment https://forums.phpfreaks.com/topic/202658-manipulating-a-string/#findComment-1062269 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! Link to comment https://forums.phpfreaks.com/topic/202658-manipulating-a-string/#findComment-1062274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.