note 89493 modified in function.substr by danbrown
| From: | danbrown@php.net | Date: | Wed, 11 Mar 2009 01:11:54 +0000 |
| Subject: | note 89493 modified in function.substr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-151712@lists.php.net to get a copy of this message | ||
this function return string between two delimiters
i found it very useful to get text between html tags
<?php
function strbet($inputStr, $delimeterLeft, $delimeterRight, $debug=false) {
$posLeft=strpos($inputStr, $delimeterLeft);
if ( $posLeft===false ) {
if ( $debug ) {
echo "Warning: left delimiter '{$delimeterLeft}' not found";
}
return false;
}
$posLeft+=strlen($delimeterLeft);
$posRight=strpos($inputStr, $delimeterRight, $posLeft);
if ( $posRight===false ) {
if ( $debug ) {
echo "Warning: right delimiter '{$delimeterRight}' not found";
}
return false;
}
return substr($inputStr, $posLeft, $posRight-$posLeft);
}
?>
--was--
this function return string between two delimiters
i found it very useful to get text between html tags
function strbet($inputStr, $delimeterLeft, $delimeterRight, $debug=false) {
$posLeft=strpos($inputStr, $delimeterLeft);
if ( $posLeft===false ) {
if ( $debug ) {
echo "Warning: left delimiter '{$delimeterLeft}' not found";
}
return false;
}
$posLeft+=strlen($delimeterLeft);
$posRight=strpos($inputStr, $delimeterRight, $posLeft);
if ( $posRight===false ) {
if ( $debug ) {
echo "Warning: right delimiter '{$delimeterRight}' not found";
}
return false;
}
return substr($inputStr, $posLeft, $posRight-$posLeft);
}
http://php.net/manual/en/function.substr.php