Jump to content

Manipulating a String


dyluck

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.