note 17411 added to function.preg-match-all
| From: | info at onlinetools dot org | Date: | Fri, 07 Dec 2001 12:07:34 +0000 |
| Subject: | note 17411 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21863@lists.php.net to get a copy of this message | ||
I came up with this small function to get the content of all specified tags in a string, quite handy
sometimes...
/*
Function untag($string,$tag,mode){
written by Chris Heilmann (info@onlinetools.org)
filters the content of tag $tag from $string
when mode is 1 the content gets returned as an array
otherwise as a string
*/
function untag($string,$tag,$mode){
$tmpval="";
$preg="/<".$tag.">(.*?)<\/".$tag.">/si";
preg_match_all($preg,$string,$tags);
foreach ($tags[1] as $tmpcont){
if ($mode==1){$tmpval[]=$tmpcont;}
else {$tmpval.=$tmpcont;}
}
return $tmpval;
}
--
http://www.php.net/manual/en/function.preg-match-all.php
http://master.php.net/manage/user-notes.php?action=edit+17411
http://master.php.net/manage/user-notes.php?action=delete+17411
http://master.php.net/manage/user-notes.php?action=reject+17411