My PHP code is generating 495 HTML pages from 495 txt files and working correctly. But right now, I'm trying to change it as a way to change the value of title tag dynamically; so I'm trying to replace %TITLE%
with $Oneline
that is the first line of each txt pages.
I have tried many syntaxes such as prg_replace
, str_replace
and much more all seems unsuccessful. In fact those lines of codes change nothing on my HTML pages.
To be more clear:
- Trying to replace
%TITLE%
with$Oneline
. $Oneline
is the first line of the txt file.
Thanks for any help.
<?php
for ($i = 1; $i <= 495; $i++)
{$j = 1;
$SousrceFile = @fopen($SousrceFile, 'r') ;
$TargetFile = fopen($TargetFile, 'w+') ;
fwrite($TargetFile, "<title>%TITLE%</title>\n");
while ($Oneline = @fgets($SousrceFile, 4096))
{$j = $j + 1;
if (strlen($Oneline) !==0)
{
$title = $Oneline;
$newTitle = preg_replace('%TITLE%', $title, $newTitle,1 );
...?>