0

I am trying to add text inside a html tag:

$html = '<html>
<head>
   <title>title</title>
</head>
<body style="background-color:yellow;">
   <p>some text</p>
</body>
</html>';

now I want this to appear at the end of the body tag:

$replacement = '<footer>Footer Text</footer>';

so that the result would look like this:

<html>
<head>
   <title>title</title>
</head>
<body style="background-color:yellow;">
   <p>some text</p>
   <footer>Footer Text</footer>
</body>
</html>

I looked for a similar answer with preg- or ereg replace but there only where solutions where the text is replaced completely.

Thanks!

1 Answer 1

2
$new_html= str_replace("</body>", "<footer>Footer Text</footer></body>", $html);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.