Skip to content

Instantly share code, notes, and snippets.

@darcyclarke
Last active May 27, 2016 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darcyclarke/27250f8a00b25ede1e57a310727e62ff to your computer and use it in GitHub Desktop.
Save darcyclarke/27250f8a00b25ede1e57a310727e62ff to your computer and use it in GitHub Desktop.
Strip text out from between two strings
<?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