0

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 retrieved 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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Saasaan
  • 83
  • 1
  • 7
  • Possible duplicate of [How to change the HTML page title dynamically generated by PHP code](http://stackoverflow.com/questions/39228296/how-to-change-the-html-page-title-dynamically-generated-by-php-code) – Andrew Aug 30 '16 at 18:54
  • I suggest you to use [DOM](http://php.net/manual/en/class.domdocument.php), if I understand you correctly – konstantin_doncov Aug 30 '16 at 20:19

1 Answers1

4
fwrite($newFile, "<title>{$newTitle}</title>\n");
Aaron
  • 1,208
  • 1
  • 9
  • 21