Jump to content

How does PHP appear as Html/CSS on browser source codes?


dezinerite

Recommended Posts

I've been theming a Wordpress site this week and I started wondering how the PHP files that show only PHP codes come up as HTML when you look at the page's source code on the browsers? How does that work exactly?

 

I don't know much about PHP but I really want to learn.  Where are all these HTML codes hiding, when all the files are coded in PHP? :confused:

Link to comment
Share on other sites

When you request a HTML page from the server, you are simply sent the contents of the HTML file, in other words the raw HTML 'code'. When you request a PHP page however things go slightly differently. Once the server receives a request for a PHP file it will start to 'parse' the file. Then as Garethp says, there are various commands that will output data, or in other words send information to the clients screen. Your browser has no idea of the contents of a php file, it simply requests the page then accepts the information the server sends back to it.

 

As a real life example. Imagine you wish to know information about students whom attend a certain school and this information is stored in a file in the school. If this information was publicly available you would walk into the school, request the list and you would be handed a copy. This is the equivalent of requesting an HTML page, you are just given a full copy of the original file. Since this information is of a private nature however it's far more likely you wouldn't be allowed to view the list. Certain information might be in the public domain though, such as number of students attending. To carry on the same analogy, you would walk into the office and request the file. This time however, instead of giving you the file the receptionist will open the file and start reading through it, when they come across bits of information you can have they will give it to you. This is the equivalent of PHP. A parser simple performs all the tasks it is told to do (in much the same way a clerk/receptionist might do), including passing information back to the client when told to. After requesting the file, all the client sees is the information the parser is told to send.

Link to comment
Share on other sites

Thanks for the reply guys, I think I'm starting to understand it.  But let's say I'm the admin of the php site and I can access all the site's files and database.

 

Where will these Html codes within the PHP be available (e.g. sticking with the Wordpress example):

 

The other day I was adding custom fields to the theme and I only had to paste this code:

 

<?php the_meta(); ?>

 

...and on the browser source code it looked like this:

 

<ul class='post-meta'>
<li><span class='post-meta-key'>Sample Text:</span> Sample Text</li>
<li><span class='post-meta-key'>Sample Text:</span> Sample Text</li>
</ul>

 

As the admin, where is the html code located; is it in the MySQL database?

 

Thanks.

Link to comment
Share on other sites

It could be anywhere, depends how the application was designed. There aren't too many standards, especially in an application like wordpress. In your case, you'll want to find the function definition for the_meta() and go from there.

Link to comment
Share on other sites

So that means the Html codes are definitely somewhere in the files/database, is this correct? Before this, I didn't know that Html was used with Php in this manner.

 

Thanks a lot for the replies, I will spend some time this evening looking through the Wordpress files.  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.