[ create a new paste ] login | about

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

PHP, pasted on Jul 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

function replace_between($str, $needle_start, $needle_end, $replacement) {
    $pos = strpos($str, $needle_start);
    $start = $pos === false ? 0 : $pos + strlen($needle_start);

    $pos = strpos($str, $needle_end, $start);
    $end = $start === false ? strlen($str) : $pos;
 
    return substr_replace($str,$replacement,  $start, $end - $start);
}

$string = "<tag>i dont know what is here</tag>";

echo replace_between($string, '<tag>', '</tag>', '');


Output:
1
<tag></tag>


Create a new paste based on this one


Comments: