助けが必要です。私は正規表現を調べましたが、その実装をまだ完全には理解していません。親に指定されたクラスまたは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?
}
}
これが初心者の質問である場合は申し訳ありませんが、お時間をいただきありがとうございます!:)
-パット