note 110667 added to ref.strings
| From: | holger1 at zentralplan dot com | Date: | Wed, 21 Nov 2012 01:46:30 +0000 |
| Subject: | note 110667 added to ref.strings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192050@lists.php.net to get a copy of this message | ||
This function returns an array of all fragments within $str between $start and $end.
Example: $image_tags = string_fragment($source, "<img ", ">", TRUE);
<?php
function string_fragment($str, $start, $end, $all) {
# $all == TRUE: $start and $end included; $all == FALSE: $start and $end excluded
$fragments = array(); $ce = "UTF-8";
while (mb_substr_count($str, $start, $ce)) {
$offset = mb_strpos($str, $start, 0, $ce);
if ($all) $len = 0; else $len = mb_strlen($start, $ce);
$rest = mb_substr($str, $offset + $len, mb_strlen($str, $ce), $ce);
if (mb_substr_count($rest, $end, $ce)) {
if ($all) $len = mb_strlen($end, $ce); else $len = 0;
$fragments[] = mb_substr($rest, 0, mb_strpos($rest, $end, 0, $ce) + $len, $ce);
}
$str = mb_substr($str, $offset + 1, mb_strlen($str, $ce), $ce);
}
return $fragments;
}
?>
----
Server IP: 69.147.83.199
Probable Submitter: 85.179.144.85
----
Manual Page -- http://www.php.net/manual/en/ref.strings.php
Edit -- https://master.php.net/note/edit/110667
Del: integrated -- https://master.php.net/note/delete/110667/integrated
Del: useless -- https://master.php.net/note/delete/110667/useless
Del: bad code -- https://master.php.net/note/delete/110667/bad+code
Del: spam -- https://master.php.net/note/delete/110667/spam
Del: non-english -- https://master.php.net/note/delete/110667/non-english
Del: in docs -- https://master.php.net/note/delete/110667/in+docs
Del: other reasons-- https://master.php.net/note/delete/110667
Reject -- https://master.php.net/note/reject/110667
Search -- https://master.php.net/manage/user-notes.php