Saasaan Saasaan - 3 months ago 21
PHP Question

Change string inside a PHP code

I have asked a question in this post

but it might look some confusing and I found no relative response, so I make it quiet simple.

the code is:

<?php
$newTitle = 'string retreved from somewhere';
fwrite($newFile, "<title>oldTitle</title>\n");
?>


I want to replace
oldTitle
with
$newTitle

I have tried this:

$myTitle = preg_replace('/(<title>)(.*?)(<\/title>)', $newtitle, $myTitle);


Thanks

Answer
fwrite($newFile, "<title>{$newTitle}</title>\n");
Comments