[ create a new paste ] login | about

Link: http://codepad.org/97REFuLm    [ raw code | output | fork ]

PHP, pasted on Oct 19:
1
2
3
4
5
6
7
8
9
10
11
<?php
  function magic_substr($haystack, $start, $end) {
    $index_start = strpos($haystack, $start) + strlen($start);
    $index_start = ($index_start > -1) ? $index_start : 0;

    $index_end = strpos($haystack, $end, $index_start); 
    $length = ($index_end > -1) ? $index_end - $index_start : strlen($end);
    return substr($haystack, $index_start, $length);
  }    
      $string = "Hey there world!";
  echo magic_substr($string, "there ", "!");


Output:
1
world


Create a new paste based on this one


Comments: