Entry
How do I find "tagname", "attributen", and "data" from "<tagname attributename=attributevalue>data</
Dec 1st, 2003 12:59
Jakub Vrana, Elie Medeiros,
If it is as simple as in the question, it's not too difficult. It
became more difficult if inside <> can be more attributes, values can
be quoted or unqoted, e.t.c.
<?php
ereg("<([^ ]*) ([^=]*)=([^>]*)>([^<]*)</", $string, $regs);
/*
for "<tag attribute=value>data</" will be in $regs:
$regs[1] = "tag";
$regs[2] = "attribute";
$regs[3] = "value";
$regs[4] = "data";
*/
?>
This will catch only first tag. If you want to catch all tags, take a
look at preg_match_all().