note 32245 deleted from function.explode by bjori
| From: | bjori@php.net | Date: | Mon, 25 Sep 2006 08:13:48 +0000 |
| Subject: | note 32245 deleted from function.explode by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117609@lists.php.net to get a copy of this message | ||
Note Submitter: stefan at NOSPAM dot elakpistol dot com
----
This function handles HTML-tags as "words", so each tag will become a single element in
the array that is returned.
<?php
function explode_tags($chr, $str) {
for ($i=0, $j=0; $i < strlen($str); $i++) {
if ($str{$i} == $chr) {
while ($str{$i+1} == $chr)
$i++;
$j++;
continue;
}
if ($str{$i} == "<") {
if (strlen($res[$j]) > 0)
$j++;
$pos = strpos($str, ">", $i);
$res[$j] .= substr($str, $i, $pos - $i+1);
$i += ($pos - $i);
$j++;
continue;
}
if ((($str{$i} == "\n") || ($str{$i} == "\r")) && (strlen($res[$j]) ==
0))
continue;
$res[$j] .= $str{$i};
}
return $res;
}
?>