# HTML --> PHP (Or automated modification of HTML)



## CJTE (Sep 18, 2007)

Good Morning!
Not for me though, I could be doing better...
From where I stand right now, I need to do one of two things, unless there is something I don't know.
First, I will start with what I am trying to accomplish.
I use blogger (The blog service Google bought out a few years ago). Which publishes back to my own PHP Server. I want to import the title/contents of my blog entries into /blog.php, but keep the same theme I'm using (navigation, etc. etc. etc.).

Option 1 is find a way to import multiple HTML files (all of which start with <DOCTYPE/HTML> and end with

Option 2 is find a script that can be automated to clear the html, head, title, and body tags out of a file, and leave just the content of the body, so I can use something like require('blog/index.html')

Maybe its the sleep deprivation getting to me, again.


----------



## 4HiMarks (Jan 21, 2004)

I'm not sure what you're trying to accomplish. I don't know anything about blogger as I don't blog, but surely if you have your own PHP server you could blog directly on it (with appropriate scripts, of course) and dump blogger completely. Or are you looking to convert so this would be a one-time thing, in which case I would suggest using Dreamweaver or something to import.


----------



## Mark Holtz (Mar 23, 2002)

Hmmm.... how to explain this....

HTML is the actual page code that causes web pages to be rendered. PHP is a scripting language that sends the code to the browser. To explain better....

In HTML, if you want a bulleted list that prints out a list of items from 1-10, your code would look like this:

```
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
```
To do the same thing in PHP, it would look something like this:

```
<?php

echo "<ul>";

for ($i=1; $i<=10; $i++) {
    echo "<li>".$i."</li>";
}

echo "</ul>";

?>
```
When you look at the source output, they are both the same. However, one is more easily modifiable than the other if I wanted 150 numbered bullet points instead of 10.

How it is interpreted is dependent on how the web server is configured. Most web servers treat .htm and .html files are straight outputs, while .php and .jsp are run through interpreters. (Yes, you can configure a web server to also parse .html as .php).


----------



## CJTE (Sep 18, 2007)

I accomplished this, temporarily at least, with an IFRAME.
When an end user goes to (blog.html), it loads my html page, and within the contend div, there is an iFrame which loads /blog/index.html

I'm using blogger because of it's collaboration (and I was too lazy to look up/setup anything else).

I was hoping for something like the following.

/blog.php

```
echo <div id="content">
include('/blog/index.html');
echo </div>
```
Where blog.php is a file I created, and /blog/index.html is a file that's published on my server from blogger.

I think if I had a script that would strip the html,head, and body tags out of index.html, the above would work.
I could manually edit the file but everytime someone publishes a blog post and its uploaded to my webserver, /blog/index.html is replaced.

So like I said, for now, i've used an iframe.



Mark Holtz said:


> Hmmm.... how to explain this....
> 
> HTML is the actual page code that causes web pages to be rendered. PHP is a scripting language that sends the code to the browser. To explain better....
> 
> How it is interpreted is dependent on how the web server is configured. Most web servers treat .htm and .html files are straight outputs, while .php and .jsp are run through interpreters. (Yes, you can configure a web server to also parse .html as .php).


I understand that. CGI/Perl is also server side, and there are atleast 2 ways that I know of to tell my web server to parse html/htm as php, the latter of which is very helpful if you've built an html site, are converting to php, and don't want to lose any of your links (or manually change all internal links to .php), or I believe you can use (atleast in apache) mod_rewrite, so as not to lose any links.


----------



## Mark Holtz (Mar 23, 2002)

It's called a typo. It's fixed on my original post. 

Depending on how deep you want to go, you may want to consider setting up a test web server on your local network to test things out, then posting on the live server. I can give you the solution that I used. YMMV.


----------



## CJTE (Sep 18, 2007)

Mark Holtz said:


> It's called a typo. It's fixed on my original post.


I didn't mean any hard feelings mate. It was a genuine question, since I don't "code" in PHP, I didn't know if there was some kind of rule that stated when [*]$var[*] is seen, the second [*] closes the tag.
My thoughts behind that were since it's already in a 
, the server knows how to render it on the client side? I don't know.
So, please accept my apology on that note, because I was trying to be genuine, not a jerk.



Mark Holtz said:


> Depending on how deep you want to go, you may want to consider setting up a test web server on your local network to test things out, then posting on the live server. I can give you the solution that I used. YMMV.


I assume you understand what I have going on then? Or do you need further clarification? Please don't take that offensively, I have a horrible habit of blurting things out and then having to come back and explain what I was trying to say, because I make too many assumptions. (On and off the intertoob'z).

For what it's worth, the site that I'm working is on a test server, but the test server is (privately) live, so the client can see the progress.


----------



## Mark Holtz (Mar 23, 2002)

CJTE said:


> I didn't mean any hard feelings mate. It was a genuine question, since I don't "code" in PHP, I didn't know if there was some kind of rule that stated when [*]$var[*] is seen, the second [*] closes the tag.
> My thoughts behind that were since it's already in a
> , the server knows how to render it on the client side? I don't know.
> So, please accept my apology on that note, because I was trying to be genuine, not a jerk.



You misunderstood me then. I made a bleeping stupid mistake even in an example, and I was not happy about it. See what happens when you do a quick reply while on a phone with a customer while they are waiting for their XP machine to boot up, and their company loads all sorts of security software before they really get access to the desktop.

Yup, that's my life.

Another part of my life was the District 39 Toastmasters website, which I managed from January, 2007 until December, 2009. (I am on hiatus). During that time, I went from very little knowledge of PHP and no knowledge of MySQL to building a kick-ass website. You just need plenty of time and patience, but you soon discover that it is FUN!

Anyways, what I have done is built a test server using Ubuntu and ISPConfig. When I built the system, Ubuntu 9.04 and ISPConfig 2 was the released versions. Since then, there have been upgrades, but for my needs, it really doesn't matter. The ISPConfig software was designed to be a open-source virtual-hosting manager for web hosting. My needs were slightly different: I wanted it for testing purposes for testing out code before uploading it to a live server. Some of the included software in my install for web pages includes PHP 5, Ruby, Python, CGI, MySQL, and so on. After the install is complete, I added on phpMyAdmin for initial testing of MySQL calls until I implemented the calls into my own code. The nice part? This is the exact same code that is run on commercial web servers (using a different interface from ISPConfig, of course). While I did install the mail modules, e-mail is unused.

I elected to build a separate box from my main system. Yes, I know that you can run it as a virtual image on your regular box, but at the time, my system wasn't that beefy yet. I did the initial development on a old Celeron 500MHz box, and upgraded to a Pentium III 1.5 GHz box. In both cases, the machines were about to be junked.


----------



## CJTE (Sep 18, 2007)

Mark Holtz said:


> You misunderstood me then. I made a bleeping stupid mistake even in an example, and I was not happy about it. See what happens when you do a quick reply while on a phone with a customer while they are waiting for their XP machine to boot up, and their company loads all sorts of security software before they really get access to the desktop.
> 
> Yup, that's my life.


Hahahahaha! That kind of stuff happens to me, *a lot*. Trying to hold two or 3 conversations at once and injecting subject matter from one conversation into another one. Or trying to work with one person and give someone else a "quick response" and then figure out a few hours later you told them something a little outside the scope.



Mark Holtz said:


> Another part of my life was the District 39 Toastmasters website, which I managed from January, 2007 until December, 2009. (I am on hiatus). During that time, I went from very little knowledge of PHP and no knowledge of MySQL to building a kick-ass website. You just need plenty of time and patience, but you soon discover that it is FUN!


That's basically where I'm at. I don't do web development, and for a good reason. My creative side has very much diminished over the last few years and I have the same ability to do math that I've had since 4th grade so doing any language beyond HTML is pretty much out of the question.
I messed with PHP a few years ago (as in, I spent maybe a week on it), but a project was dropped in my lap for a friend of a friend.



Mark Holtz said:


> Anyways, what I have done is built a test server using Ubuntu and ISPConfig. When I built the system, Ubuntu 9.04 and ISPConfig 2 was the released versions. Since then, there have been upgrades, but for my needs, it really doesn't matter. The ISPConfig software was designed to be a open-source virtual-hosting manager for web hosting. My needs were slightly different: I wanted it for testing purposes for testing out code before uploading it to a live server. Some of the included software in my install for web pages includes PHP 5, Ruby, Python, CGI, MySQL, and so on. After the install is complete, I added on phpMyAdmin for initial testing of MySQL calls until I implemented the calls into my own code. The nice part? This is the exact same code that is run on commercial web servers (using a different interface from ISPConfig, of course). While I did install the mail modules, e-mail is unused.
> 
> I elected to build a separate box from my main system. Yes, I know that you can run it as a virtual image on your regular box, but at the time, my system wasn't that beefy yet. I did the initial development on a old Celeron 500MHz box, and upgraded to a Pentium III 1.5 GHz box. In both cases, the machines were about to be junked.


Ehhh, forget virtual images. Its better to have a physical box in a physical location for this kind of stuff.
Ive got a Dell Optiplex G1 (440Mhz) which functions as a print/file server to a small LAN. It runs IIS on the "production" side, which enables IPP, WebDAV, and Terminal Services over a Browser interface. I installed XAMPP (From apache friends) which includes MySQL, PHP, Apache, Perl, Webalizer, Filezilla, Mercury Mail, and a WebDAV server. Modified the install for what I needed, and I'm using that for my testing/client development. Anything I like I can test on apache and then move it over to the IIS side.
And, now I can use perl scripts for my stuff hosted on the IIS side.

The thing about virtual machines is that they're only available where ever you put them. Unless you download a copy from a webserver. They're not very portable if you're running them on a desktop (if the desktop loses power, or internet connectivity).


----------



## Mark Holtz (Mar 23, 2002)

So, back to the install.... the prep work. First, know your local network. You want to look at your network configuration by going into a command prompt and typing IPConfig /all. If your home network is anything like my network, there is a external IP address that is assigned by your ISP, and a NAT mapping with a IP address of 10.10.x.x or 196.168.x.x . You will also need to know your gateway address, subnet mask, and DNS server addresses. For me, my network setup is something like this:

192.168.0.1 - Gateway
192.168.0.2-192.168.0.25 - DHCP assigned addresses
192.168.0.201-192.168.0.209 - Windows machines range
192.168.0.210 - Web Server
192.168.0.245 - Wireless Gateway
192.168.0.251 - Laser Printer (.250 was retired and the printer no longer exists)
192.168.0.255 - NEVER USE!!!!
Subnet mask: 255.255.255.0

Your network configuration will be different. Whis is this important? Remember, you are setting up a network server. Initially, when the machine boots up, it will use DHCP to grab an address. You fix it during the initial setup with fixed IP addresses. Also, you cannot duplicate IP addresses.

Anyways, once you figure out what IP address is going to be, you want to get a machine. Remember, this is going to be a dedicated box, with the goal of having it so that you only need to have a power and network cable hooked up normally, and it sits quietly in the corner as you actually access the software through FTP, http, and SSH services. You will want to go into the BIOS and configure it to boot off the CD-ROM first, then the hard drive. Also, you do NOT want it to stop if there is a missing keyboard or monitor (yes, it's may beep and complain during boot up. Oh well). Initially, you will need to hook up a monitor and keyboard for the drive format and core system install. However, early on, you will install the SSH services and change it from DHCP to static IP address. Once that's done, you will then log in as root and control the system through a terminal program like PuTTY.

Yes, some software is installed on your Windows machine. You will need to install a FTP client (like FileZilla), a SSH terminal Program (like PuTTY), and a ISO burner for the Linix Boot CD(like ImgBurn).

Once you have that all installed, you follow the setup instructions for setting up the server (See this page). Use extremely simple passwords for this server(e.g. Fluffy), as nobody on the outside world can access this server and tape it to the outside of the box. Once completed, you install ISPConfig (see this page), then the phpMyAdmin through this page. Ignore the web mail clients... they really won't work unless you keep the mail local.

The next trick is to access the server through a domain name rather than a IP address. Using the ISPConfig manager, you will create a web site with all services and a dummy domain name. I use the TLD domain of .test because it's a known invalid TLD (see this Wiki article) per RFC2606. Since it's local, it doesn't matter. The test site is district39.test . You will not be able to resolve it. However, I can because I modify the HOSTS file on the computer to look like this:

```
district39.test 192.168.0.210
www.district39.test 192.168.0.210
```
thus, when I type in that domain name, the site comes up for me. (Please note that I couldn't get BIND services to work because of a lack of a secondary DNS server. So, I cheated).

Some gotchas to watch out for:
Because of downloading and installing, you can expect to spend 2-3 hours setting up the server.
Unless things changed, there is no .htaccess file
The user that is created to update the website must have the "Administrator" privilege checked off in ISPConfig, otherwise you won't be able to upload a site and have it work.
The logon information in your PHP scripts should be kept in a separate file that is loaded. Between your test server and the actual live server, the u/p/server is DIFFERENT.
Also, I tend the use the following PHP code when referring to my own custom library: include($_SERVER["DOCUMENT_ROOT"]."/hidden_common_directory/my_own_routine_library.inc.php") That way, differences between the test server and the live server are automatically resolved.
Yes, you do need to have some knowledge of Linux and Networks to get this to work. Trust me, I had my own trial and error. But, it works well for me. Your mileage will vary.


----------



## Mark Holtz (Mar 23, 2002)

(The above was written offline and uploaded)



CJTE said:


> That's basically where I'm at. I don't do web development, and for a good reason. My creative side has very much diminished over the last few years and I have the same ability to do math that I've had since 4th grade so doing any language beyond HTML is pretty much out of the question.


Unfortunately, HTML will not allow you to have interaction with a MySQL database or have customized web pages. Have scripts like PHP allow you to do that.


CJTE said:


> Ive got a Dell Optiplex G1 (440Mhz) which functions as a print/file server to a small LAN. It runs IIS on the "production" side, which enables IPP, WebDAV, and Terminal Services over a Browser interface.


Having worked at a ISP for several years which was a FreeBSD shop, I'm biased towards the Linux/Unix/BSD solutions instead of the IIS solution. We found that the Windows server required more care, feeding, and burping than *nix solutions. In addition, in price comparisons with various web hosting services, IIS tended to be slightly more expensive per month than *nix solutions. The fun part: My original test server ran for almost 2 years non-stop without rebooting even with updates, and was taken down only when I received a better box.


----------



## CJTE (Sep 18, 2007)

Mark Holtz said:


> (The above was written offline and uploaded)


I'll get to that in a minute...



Mark Holtz said:


> Unfortunately, HTML will not allow you to have interaction with a MySQL database or have customized web pages. Have scripts like PHP allow you to do that.


No, ofcourse it won't. It's a mark-up language, not a scripting language. One of the many reasons PHP is powerful is because it's server side.



Mark Holtz said:


> Having worked at a ISP for several years which was a FreeBSD shop, I'm biased towards the Linux/Unix/BSD solutions instead of the IIS solution. We found that the Windows server required more care, feeding, and burping than *nix solutions. In addition, in price comparisons with various web hosting services, IIS tended to be slightly more expensive per month than *nix solutions. The fun part: My original test server ran for almost 2 years non-stop without rebooting even with updates, and was taken down only when I received a better box.


Ahhh yes. The joys of *NIX.
As stated earlier, my logical mind HALTs at things such as math. *NIX browsers are fun to diagnose but unlike Windows, there's a lot more elements to try to learn and understand, a lot of different solutions, and the tiniest things can cause the biggest problems. I'm not saying windows isn't a serious problem all on it's own, but windows is a devil I can wrap my head around. Macintosh, too (but the price pushes me away).
*NIX has more power, and is more universal in what can be done with it, but it leaves much to be desired on the "just beyond simple" side.
Sure, you can take a distro like Ubuntu and set it up for grandma to check her email and update her facebook (yes, my 79 year old grandmother does these things), but I can't do much with it. When I'm less lazy and more apt to try it, I get frustrated easily by things not working or not having support (yet).

My box runs XP headless. At 440mhz and an (upgraded) 384mb of RAM, I wouldn't want anyone to try and work with it, let alone trust them to put it back together (I work{ed} with some extremely competent people, who worked with some extremely incompetent partners!).
It serves it's purpose pretty well. The corporate A/V runs on it, and it's pretty rare that I log onto it remotely to do web-browsing with so I don't worry much about drive-by attacks. When the network gets infected my machine is usually far down the line of being hit, and by the time something would get to it I'm usually there stopping it anyway.
I reboot it Tuesday nights (patch tuesday, haha), but when I get busy it's gone weeks at a time without a fuss.
The most trouble it ever has is when one of the service-guys come out to work on the printer and they disconnect the USB cable and don't reconnect it.


----------



## CJTE (Sep 18, 2007)

Mark Holtz said:


> So, back to the install.... the prep work. First, know your local network. You want to look at your network configuration by going into a command prompt and typing IPConfig /all.


I prefer to know who I am and what's going on around me to. A lot of the current generation routers (if not all) have a device table that'll tell you what's connected to them. Unfortunately, if they're behind another device (like any Wireless Ethernet Bridge) depending on that devices configuration they may not show up (Show up as a single device with no name and the connecting devices mac address). The other kind I like is when in client-bridge mode on DD-WRT devices, any devices connected to it show up on the host router with the proper name and IP, but all those IPs are bound to the single MAC address of the secondary router.



Mark Holtz said:


> 192.168.0.255 - NEVER USE!!!!


You can't use 192.168.0.0 either 



Mark Holtz said:


> Your network configuration will be different. Whis is this important? Remember, you are setting up a network server. Initially, when the machine boots up, it will use DHCP to grab an address. You fix it during the initial setup with fixed IP addresses. Also, you cannot duplicate IP addresses.


You can't set the same ip address on 2 different machines, but if you set your static IP address within the DHCP Routers range it can pass out that address. Though if it sees an active client with the address it usually won't.



Mark Holtz said:


> However, early on, you will install the SSH services and change it from DHCP to static IP address. Once that's done, you will then log in as root and control the system through a terminal program like PuTTY.


This is a very good tutorial, however I'd definitely recommend securing the super user and logging in as a regular user for anything that one might need. ROOT should only be used, IMO, in emergency cases. SU should be suitable for everything else.



Mark Holtz said:


> Yes, some software is installed on your Windows machine. You will need to install a FTP client (like FileZilla), a SSH terminal Program (like PuTTY), and a ISO burner for the Linix Boot CD(like ImgBurn).


 I've never been a fan of Filezilla but seeing as that it came by default with XAMPP, I checked it out. It's simple to use and it's a newer version than my last trial with it, it seems to be ok. And, It had the option to be installed as a service so I didn't have to look at its ugly GUI unless I wanted to actually manage it.
You should look into CDBurnerXP. ImgBurn, InfraRecorder (portable app), and even Alex Feinman's ISO recorder have failed me where CDBurnerXP has not (and it works on more than just XP, with more than just CDs). My second favorite is definitely ISO Recorder, because it can be installed to hook in with explorer. (Right click, burn ISO).



Mark Holtz said:


> Once you have that all installed, you follow the setup instructions for setting up the server (See this page). Use extremely simple passwords for this server(e.g. Fluffy), as nobody on the outside world can access this server and tape it to the outside of the box. Once completed, you install ISPConfig (see this page), then the phpMyAdmin through this page. Ignore the web mail clients... they really won't work unless you keep the mail local.


I'm still not a fan of simple passwords, but you did remind me that this is based towards an internal only environment. I'm definetly going to check out this ispconfig.org that you mentioned earlier though, it sounds like a lot!



Mark Holtz said:


> The next trick is to access the server through a domain name rather than a IP address. Using the ISPConfig manager, you will create a web site with all services and a dummy domain name. I use the TLD domain of .test because it's a known invalid TLD (see this Wiki article) per RFC2606. Since it's local, it doesn't matter. The test site is district39.test . You will not be able to resolve it. However, I can because I modify the HOSTS file on the computer to look like this:
> 
> ```
> district39.test 192.168.0.210
> ...


Windows\System32\Etc\Hosts... Always a reliable band-aid to an unreliable DNS server.
And hey, as long as you're there, you can tag some of those pesky ad-hosting sites with your localhost address as well to stop them in their tracks!



Mark Holtz said:


> Some gotchas to watch out for:
> Because of downloading and installing, you can expect to spend 2-3 hours setting up the server.
> Unless things changed, there is no .htaccess file
> The user that is created to update the website must have the "Administrator" privilege checked off in ISPConfig, otherwise you won't be able to upload a site and have it work.
> ...


No .htaccess file? is that something you can change in the configuration (like in apache's httpd.conf you can allow override).


----------



## Mark Holtz (Mar 23, 2002)

CJTE said:


> You can't use 192.168.0.0 either


Once upon a time, a so-called network admin wants to set up a NAT network using 127.0.x.x . What wrong with that? Go back to your network books.


CJTE said:


> This is a very good tutorial, however I'd definitely recommend securing the super user and logging in as a regular user for anything that one might need. ROOT should only be used, IMO, in emergency cases. SU should be suitable for everything else.


Even the tutorial's author says that it is not recommended.

As for Filezilla, ImgBurn, and your choices of alternatives... whatever works. Those three solutions is what I use and are small downloads since there are other readers reading what we write. There are other good alternatives, and I have even downloaded and used some of your suggestions.


CJTE said:


> I'm still not a fan of simple passwords, but you did remind me that this is based towards an internal only environment. I'm definetly going to check out this ispconfig.org that you mentioned earlier though, it sounds like a lot!


It will frighten you that I even have the logons and passwords glued to this test server. But only one person uses that server, and that's me. If this was more production, the passwords would look like jibberish.


CJTE said:


> No .htaccess file? is that something you can change in the configuration (like in apache's httpd.conf you can allow override).


I don't know why. I have one on the actual web host to cut down on unnecessary spiders and re-write the URL.


----------

