function htmlGetTagsContent($str, $tag = 'body')
{
if (preg_match('|<' . $tag . '>(.*)</' . $tag . '>|Uis', $str, $matches)) {
return $matches[1];
} else {
return false;
}
}
function htmlGetFirstMatch($str, $regexp)
{
if (preg_match($regexp, $str, $matches)) {
return $matches[1];
} else {
return false;
}
}
function htmlSetFirstMatch($str, $old_regexp, $new_str)
{
if (preg_match($old_regexp, $str, $matches)) {
return str_replace($matches[1], $new_str, $str);
} else {
return $str;
}
}
function htmlDeleteTag($str, $tag)
{
$re = '|(<' . $tag . '>.*</' . $tag . '>)|Usim';
return htmlSetFirstMatch($str, $re, '');
}
Listing 21.3. Funkcje odpowiedzialne za odczytywanie oraz usuwanie znaczników z kodu HTML
Rozdział 21. Identyfikacja rekordów na podstawie wartości slug