Skip to content

Instantly share code, notes, and snippets.

@vicgonvt
Created August 4, 2018 16:20
Show Gist options
  • Select an option

  • Save vicgonvt/994dfcc31cad0c490e3e91c8bc471e20 to your computer and use it in GitHub Desktop.

Select an option

Save vicgonvt/994dfcc31cad0c490e3e91c8bc471e20 to your computer and use it in GitHub Desktop.

Revisions

  1. vicgonvt revised this gist Aug 4, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions getBetween_v2.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    function str_between($string, $start, $end, $innerOnly = true, $remove = false) {

    if (($startPosition = strpos($string, $start)) === false || ($endPosition = strpos($string, $end)) === false) {
  2. vicgonvt created this gist Aug 4, 2018.
    19 changes: 19 additions & 0 deletions getBetween_v2.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function str_between($string, $start, $end, $innerOnly = true, $remove = false) {

    if (($startPosition = strpos($string, $start)) === false || ($endPosition = strpos($string, $end)) === false) {
    return false;
    }

    if ($innerOnly) {
    $startPosition += strlen($start);
    $endPosition -= strlen($end);
    }

    $between = substr($string, $startPosition, ($endPosition + strlen($end)) - $startPosition);

    if ($remove) {
    return str_replace($between, '', $string);
    }

    return $between;
    }