I'm trying to read a file, then search the file line by line for HTML tags. And then perform some specific actions on each tag (well some of them). Such as assigning default values to input tags and things of that nature. Then write a new file with these modified tags. It seems regular expressions would be the way to go. However i don't know what the hell i'm doing with them.
For simplicity's sake i'd like to read the file in line by line, then try and assign all the tags to an array then just display the tags as a first step. However i can't seem to nail that down. I tried something like this...
$lines = file('sample.php');
foreach ($lines as $line_num => $line) {
$tags = preg_split ("/<?>/",$line);
$size = sizeof($tags);
for($x = 0; $x < $size; $x++) {
echo htmlspecialchars($tags[$x])."<BR>";
}
}
But of course this doesn't work as it just splits a line like this:
<td> Some text </td>
into:
$tags[0] = "<td";
$tags[1] = "Some text </td";
rather than what i want which would be:
$tags[0] = "<td>";
$tags[1] = "</td>";
Is this code on the complete wrong track? Am i wasting my time trying to do with preg_split ? Is there a better way to do this? Any help would be greatly appreciated.