Hi!
I hat mal den table_of_contents UDT geändert. Funktioniert auch, allerdings nur, wenn auch nur die attribute name oder id vorhanden sind. Wenn ein weiteres attribut hinzugefügt wird, funktioniert er nicht mehr. Kann mir jemand helfen, dass die funktion noch funktioniert, wenn ich beispielsweise noch ein class attribut drinhab, das aber mal vor, mal nach name oder id stehen kann?
preg_match_all("/(.*)/i", $page_contents, $match);
http://wiki.cmsmadesimple.org/index.php ... f_contents
preg_match_all frage zu table_of_contents UDT
preg_match_all frage zu table_of_contents UDT
Last edited by SimonSchaufi on Tue Aug 14, 2007 6:58 am, edited 1 time in total.
Re: preg_match_all frage zu table_of_contents UDT
Gehts etwas einfacher?
Code: Select all
function get_element($realname, $type, $string)
{
$return = array();
$name = preg_quote($realname, '/');
preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*((\/)?>|>(.*)<\/$name>)/msiU", $string, $matches, PREG_SET_ORDER);
for ($i = 0; $i < count($matches); $i++)
{
$return[$i]['attribs'] = array();
if (!empty($matches[$i][2]))
{
preg_match_all('/((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(\S+))\s/msiU', ' ' . $matches[$i][2] . ' ', $attribs, PREG_SET_ORDER);
for ($j = 0; $j < count($attribs); $j++)
{
$return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1];
}
}
}
return $return;
}
$test = get_element("a", "name", '<a id="bla" name="packages" class="an">Packages</a>bla<a id="asdf" name="anchor">anchortest</a>');
for ($i = 0; $i < count($test); $i++)
echo '<a href="#'.$test[$i]['attribs']['name']['data'].'">'.$test[$i]['attribs']['name']['data'].'</a><br>';
Re: preg_match_all frage zu table_of_contents UDT
gibt es hier keinen preg_match Kenner im Forum?