I want to create a PHP program that could create a .php file that could read this HTML file:
<html>
<head>
<title> Hello World! </title>
</head>
<body>
</body>
</html>
It will search the <head>
and </head>
TAGS incuding the tags in between, and transfer the selected tags to header.php
So, the header.php will have this:
<head>
<title> Hello World! </title>
</head>
Additional problem is, how to insert the PHP tag <?php
in the beginning of the page and ?>
in the last part of the PHP file.
I have done this code right here, but its not yet done and i doesn't read a <head>
tag.
<?php
firstIdentifier = '<head>';
$secondIdentifier = '</head>';
$currentContent = str_replace("\n", "", file_get_contents('sourcefile.txt'));
$pattern = '/('.$firstIdentifier.')(.+?)('.$secondIdentifier.')/';
//get all text between the two identifiers, and include the identifiers in the match result
preg_match_all($pattern, $currentContent , $matches);
//stick them together with space delimiter
$contentOfNewFile = implode(" ",$matches[0]);
//save to a new file
$newFile = fopen('destinationFile.txt','a');
fwrite($newFile, $contentOfNewFile);
?>
Please Help...