Last active
May 27, 2016 03:09
-
-
Save darcyclarke/27250f8a00b25ede1e57a310727e62ff to your computer and use it in GitHub Desktop.
Strip text out from between two strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/***********************************************/ | |
/* PHP Strip Function | |
/* http://darcyclarke.me/articles/development/strip-out-text-between-two-tags-in-a-string-php/ | |
/* | |
/* Copyright 2016, Darcy Clarke | |
/* Do what you want license | |
/***********************************************/ | |
function strip($startTag,$endTag,$text,$pos=0){ | |
if(!is_integer($pos)){ | |
$pos = false; | |
return false; | |
} | |
$pos1 = strpos($text,$startTag,$pos); | |
if(!is_integer($pos1)){ | |
$pos = false; | |
return false; | |
} | |
$pos1 += strlen($startTag); | |
$pos2 = strpos($text,$endTag,$pos1); | |
if(!is_integer($pos2)){ | |
$pos = false;return false; | |
} | |
$res = substr($text,$pos1,$pos2-$pos1); | |
$pos = $pos2 + strlen($endTag); | |
return $res; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment