note 32245 modified in function.explode by aidan
| From: | aidan@php.net | Date: | Sun, 27 Jun 2004 14:16:18 +0000 |
| Subject: | note 32245 modified in function.explode by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71919@lists.php.net to get a copy of this message | ||
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;
}
?>
--was--
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;
}
?>
http://php.net/manual/en/function.explode.php