Jump to content

Recommended Posts

Lets say I have a string with the value

"Robots > Bunnies"

 

Is there any way that I could get everything between "robots" and "bunnies" and put it into its own string

 

Example:

 

<?php
function getInBetween($string, $before, $after, $newstring)
  {
  //function to get whats between $before and $after from $string and put it in $newstring
  }

getInBetween("My name is Mark.","My name is ", ".", $name);
?>

 

SO it would get what is between "My name is " and "." so it would get my name.

 

 

Ofcourse this is just an example and not what I am using it for :P

 

It's vulgar, but...

function get_mid($s, $start, $end)
{
return trim(substr($s, strlen($start), -(strlen($end))));
}

$ss = "test name test";
$n = get_mid($ss, "test", "test");
echo "name: ".$n."<br>";

You could count the strings first and pass the length, esp if repeated!

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.