I am trying to get a tag and replace it by another.
<temp01 attr01="0123" attr02="0123" attr03="0123">content</temp01>
exchange for:
<script attr01="0123" attr02="0123" attr03="0123">content</script>
detail all content and all attributes must remain the same.
$doc["prog"]->attr('new_tag_name','script');
$doc["prog"]->map('change_tag_name');
print $doc;
function change_tag_name($item)
{
$new_tab_name = trim(pq($item)->attr('new_tag_name'));
if (! empty($new_tab_name)){
$attrs = pq($item)->attr('*');
$content = pq($item)->html();
pq($item)->after("<$new_tab_name>$content</$new_tab_name>");//-
>attr($attrs);
unset ($attrs['new_tag_name']);
if ( is_array($attrs))
foreach ($attrs as $key => $value )
pq($item)->next()->attr($key,$value);
pq($item)->remove();
}
}
If anyone has any suggestions?
$newTag = preg_replace('/<([a-z0-9]+)([^>]*)>([^<]*)</\1>/', '<newtag
$2>$3</newtag>', $oldTag);