I’m new to using regular expressions in php and am trying to create a practice file to become more familiar. I occasionally work with html files that display the code as one continuous line, so I’m trying to write a simple script to open an html file and insert a carriage return/line feed after ever tag pair. I’m running into two problems:
[ol][li]The ereg_replace() function I’m using appears to be deprecated; and[/li]
[li]I’m unable to append text to the end of the matching string; the replacement overwrites the file with the literal text of the expression.[/li][/ol]
Can anybody help me?
[php]
// open file to be cleaned
$data = file_get_contents(“file.html”);
// add carriage return after each tag in data file
$clean = ereg_replace("<[[:print:]]>[[:print:]]</[[:print:]]>","<[[:print:]]>[[:print:]]</[[:print:]]>\r\n",$data);
// overwrite file with updated contents
file_put_contents(“file.html”,$clean);
[/php]