Consider an example with xnotes :
$filename = 'file.txt'; $file = file_get_contents($filename); $file = str_replace('foo', 'bar', $file); file_put_contents($filename, $file); How to make a similar replacement, only:
- We will replace in advance the unknown contents of some tag, for example,
<title> - Deletion of deletions in the source file should not be
I tried this:
$filename = 'file.php'; $file = file_get_contents($filename); $title_pattern='#<title>.+?</title>#s'; $test= str_replace($title_pattern, "Новый заголовок", $file); file_put_contents($file, $test); and another way:
$title_pattern='#<title>.+?</title>#s'; preg_match($title_pattern, $file, $matches); $test= str_replace($matches, "Новый заголовок", $file); file_put_contents($fileadr, $test) Ideally, you need to go to the file, which at the moment is not displayed in the browser, replace only the content of one tag, and do not touch the rest of what is there and do not even read it (we simply do not need it). But I suspect that this is beyond the capabilities of PHP.
Still through PHPQuery tried to do. As a result, it was possible, but the entire tabulation in the source file was broken (asked a question on this topic, so far without an answer).