我正在尝试在html标记内添加文字:
$html = '<html>
<head>
<title>title</title>
</head>
<body style="background-color:yellow;">
<p>some text</p>
</body>
</html>';
现在我希望它出现在body标签的末尾:
$replacement = '<footer>Footer Text</footer>';
所以结果看起来像这样:
<html>
<head>
<title>title</title>
</head>
<body style="background-color:yellow;">
<p>some text</p>
<footer>Footer Text</footer>
</body>
</html>
我在preg-或ereg替换中找到了类似的答案,但只有完全替换文本的解决方案。
谢谢!
答案 0 :(得分:2)
$new_html= str_replace("</body>", "<footer>Footer Text</footer></body>", $html);