1.

How to get string between two characters in php?

Answer»

Suppose we have a

$string = “[Hello there I’m=testing]”

And we want to EXTRACT the string placed between the characters between = and ].

Here’s how to do it using PHP string functions:

EXAMPLE

$str = "[Hello there I’m=testing]";
$from = "=";
$to = "]";

ECHO getStringBetween($str,$from,$to);

FUNCTION getStringBetween($str,$from,$to)
{
    $sub = substr($str, strpos($str,$from)+strlen($from),strlen($str));
    return substr($sub,0,strpos($sub,$to));
}

Output:
Testing



Discussion

No Comment Found