mirror of
https://github.com/myvesta/vesta
synced 2025-07-05 20:41:53 -07:00
str_get_between PHP function
This commit is contained in:
parent
38137b3ba9
commit
16e1000f1c
1 changed files with 30 additions and 0 deletions
|
@ -11,3 +11,33 @@ function myvesta_replace_in_file($find, $replace, $file) {
|
|||
$r=file_put_contents($file, $buf);
|
||||
return $r;
|
||||
}
|
||||
|
||||
function myvesta_str_get_between (&$text, $left_substring, $right_substring, $start=0, $do_not_return_left_substring=1, $do_not_return_right_substring=1, $left_substring_necessary=1, $right_substring_necessary=1)
|
||||
{
|
||||
$from_null=0;
|
||||
$pos1=strpos($text, $left_substring, $start);
|
||||
if ($pos1===FALSE)
|
||||
{
|
||||
if ($left_substring_necessary==1) return "";
|
||||
$pos1=$start;
|
||||
$from_null=1;
|
||||
}
|
||||
|
||||
if ($do_not_return_left_substring==1)
|
||||
{
|
||||
if ($from_null==0) $pos1=$pos1+strlen($left_substring);
|
||||
}
|
||||
$pos2=strpos($text, $right_substring, $pos1+1);
|
||||
if ($pos2===FALSE)
|
||||
{
|
||||
if ($right_substring_necessary==1) return "";
|
||||
$pos2=strlen($text);
|
||||
}
|
||||
if ($do_not_return_right_substring==1) $len=$pos2-$pos1;
|
||||
else $len=($pos2-$pos1)+strlen($right_substring);
|
||||
|
||||
$slen=strlen($text);
|
||||
if ($pos1+$len>$slen) $len=$slen-$pos1;
|
||||
|
||||
return substr($text, $pos1, $len);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue