Skip to content

Instantly share code, notes, and snippets.

@tieutantan
Last active August 12, 2022 12:22
Show Gist options
  • Save tieutantan/49b13219f1eac75ef069138553105b6a to your computer and use it in GitHub Desktop.
Save tieutantan/49b13219f1eac75ef069138553105b6a to your computer and use it in GitHub Desktop.
Get substring between two strings PHP
<?php
// https://stackoverflow.com/a/9826656
public static function get_string_between($string, $start, $end)
{
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0)
return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
@osbre
Copy link

osbre commented May 23, 2020

If use Laravel:

Str::between(arg, arg, arg)

@Amirrezarazi01
Copy link

good and useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment