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:
$newTitle = 'string retreved from somewhere';
$myTitle = preg_replace('/(<title>)(.*?)(<\/title>)', $newtitle, $myTitle);