dezinerite Posted February 13, 2010 Share Posted February 13, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/191949-how-does-php-appear-as-htmlcss-on-browser-source-codes/ Share on other sites More sharing options...
Garethp Posted February 13, 2010 Share Posted February 13, 2010 PHP has an echo code that displays things as HTML. For example echo "<a href=\"http://google.com\">Google</a>"; shows an HTML link to google Quote Link to comment https://forums.phpfreaks.com/topic/191949-how-does-php-appear-as-htmlcss-on-browser-source-codes/#findComment-1011723 Share on other sites More sharing options...
cags Posted February 13, 2010 Share Posted February 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191949-how-does-php-appear-as-htmlcss-on-browser-source-codes/#findComment-1011737 Share on other sites More sharing options...
dezinerite Posted February 14, 2010 Author Share Posted February 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191949-how-does-php-appear-as-htmlcss-on-browser-source-codes/#findComment-1012046 Share on other sites More sharing options...
trq Posted February 14, 2010 Share Posted February 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191949-how-does-php-appear-as-htmlcss-on-browser-source-codes/#findComment-1012049 Share on other sites More sharing options...
dezinerite Posted February 14, 2010 Author Share Posted February 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191949-how-does-php-appear-as-htmlcss-on-browser-source-codes/#findComment-1012112 Share on other sites More sharing options...
cags Posted February 14, 2010 Share Posted February 14, 2010 Yes the HTML will definitely be in code somewhere under a function that will look like.. function the_meta() { } Quote Link to comment https://forums.phpfreaks.com/topic/191949-how-does-php-appear-as-htmlcss-on-browser-source-codes/#findComment-1012113 Share on other sites More sharing options...
Daniel0 Posted February 14, 2010 Share Posted February 14, 2010 The HTML may not necessarily be in another file or in the database. It may also be generated by the script based on data in another format. Quote Link to comment https://forums.phpfreaks.com/topic/191949-how-does-php-appear-as-htmlcss-on-browser-source-codes/#findComment-1012121 Share on other sites More sharing options...
dezinerite Posted February 14, 2010 Author Share Posted February 14, 2010 You guys are just awesome! Thanks so much for your help, this is very encouraging! Quote Link to comment https://forums.phpfreaks.com/topic/191949-how-does-php-appear-as-htmlcss-on-browser-source-codes/#findComment-1012170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.