我需要一些帮助。我研究了正则表达式,但还没有完全理解它的实现。如果父级包含给定的类或ID,我需要一个片段来删除所有标签及其子级。
例子:
<?php
function remove_tag($find="",$html)
{
# Remove multiple #IDs and classes at once
# When given a string (separating objects with a comma)
if (is_string($find))
{
$objects = explode(',', str_replace(' ', '', $find);
} else if (is_array($find)) {
$objects = $find;
}
foreach ($objects as $object)
{
# If ID
if (substr($object,0,1) == '#')
{
# regex to remove an id
# Ex: '<ANYTAG [any number of attributes] id='/"[any number of ids] NEEDLE [any number of ids]'/" [any number of attributes]>[anything]</ENDTAG [anything]>'
}
if (substr($object,0,1) == '.')
{
# remove a class
# Ex: '<ANYTAG [any number of attributes] class='/"[any number of classes] NEEDLE [any number of classes]'/" [any number of attributes]>[anything]</ENDTAG [anything]>'
}
# somehow remove it from the $html variable?
}
}
抱歉,如果这是一个新手问题,谢谢您的宝贵时间!:)
-拍