PHP Classes

File: html2php.php

Recommend this page to a friend!
  Classes of al dev   HTML2php   html2php.php   Download  
File: html2php.php
Role: ???
Content type: text/plain
Description: Program which converts HTML to PHP code
Class: HTML2php
Author: By
Last change:
Date: 22 years ago
Size: 2,136 bytes
 

Contents

Class file image Download
<?php /* ** History: I saw programs in perl/php to convert html to php ** and wrote this class based on that. You can find those on ** search engines like google, yahoo. ** Usage: require_once("html2php.php"); $h2p = new html2php; //print "<h1>cvtflg = ". $cvtflg . " </h1>"; if ($cvtflg == 1) // cvtflg is set in start() { $h2p->file_to_change = $file_to_change; $h2p->convert(); } else $h2p->start(); */ class html2php { var $file_to_change; function start() { print ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>HTML to PHP</title> </head> <body> <form action="?cvtflg=1" method="post" enctype="multipart/form-data"> Select the HTML file to convert to PHP: <br><br> <input type="file" name="file_to_change" size="60"> <br><br> <input type="submit" value="submit"> <h1>After doing the conversion, you should save the file as a TEXT file (php file like filename.php)</h1> </form> </body> </html>'); } function convert() { print("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"); print("\n"); print("<html>\n"); print("<head>\n"); print("<title>Untitled</title>\n"); print("</head>\n"); print("\n"); print("<body>\n"); print("&lt;?php\n\n<br><br>"); // create array from file with each line an array element $file_array = file($this->file_to_change); for ($index = 0; $index < count($file_array); $index++) { $line = $file_array[$index]; //insert forward slash before quotes $line_coded = ereg_replace("\x22", "\x5c\x22", $line); $line_coded = ereg_replace("\x0d", "", $line_coded); //strip carriage returns $line_coded = ereg_replace("\x0a", "", $line_coded); //strip line feeds //change < and > to character entity name for output to HTML page $line_coded = ereg_replace("<", "&lt;", $line_coded); $line_coded = ereg_replace(">", "&gt;", $line_coded); //PHP line of code $print_me = "print(\"$line_coded\\n\");\n<br>"; print("$print_me"); } print ("<br><br>php?>"); print("</body>\n"); print("</html>\n"); } } php?>