Can someone help me get this function to work? The function should accept $HTMLstr
-- a whole page of HTML stuffed into a string that already contains a meta description in the form of:
<meta name="description" content="This will be replaced"/>
along with $content
which is the string that should replace "This will be replaced". I thought I was close with this function, but it doesn't quite work.
function HTML_set_meta_description ($HTMLstr, $content) {
$newHTML = preg_replace('/<meta name="description"(.*)"\/>/is', "<meta name=\"description\" content=\"$content\"/>", $HTMLstr);
return ($newHTML);
}
Thanks for any help!
Edit: Here's the working function.
function HTML_set_meta_description ($HTMLstr, $content) {
// assumes meta format is exactly <meta name="description" content="This will be replaced"/>
$newHTML = preg_replace('/<meta name="description" content="(.*)"\/>/i','<meta name="description" content="' . $content . '" />', $HTMLstr);
return ($newHTML);
}