I've been trying to find out the rules about embedded scripting in HTML, things like PHP and JavaScript. It seems like it doesn't really have any rules!
Part of the problem is that Google makes it impossible to search for anything other than alphanumerics so you can't search for things like <SCRIPT> or <?php. So, first question, is there *any* way now that Google rules the world to search for things like this?
Moving on, how can one find what *actually* works inside a <SCRIPT> section in HTML? Is it only javascript that really works there in 'most' browsers or are there other possibilities?
The other question is how does <?php work at all? I can't find anything that documents how or why it should allow PHP to do things. I'm maybe missing something obvious but given Google's total inability to look for such things doing any sort or searching is a bit difficult. I have O'Reilly books on HTML and PHP but neither of them really addresses how this works.
I do realise that <SCRIPT> starts client side scripting so is limited by what's implemented in browsers, however it is at least a 'proper' HTML element. <?xxx seems more of a bodge, is it actually a bodge or is there some smeantic/syntactic logic to it?
The script is a client browser script where as the php is a server side script.
Not sure if that answers your questions ?
Regards Ian Porter
www : www.codingfriends.com
On 4 Feb 2010, at 21:20, Chris G cl@isbd.net wrote:
I've been trying to find out the rules about embedded scripting in HTML, things like PHP and JavaScript. It seems like it doesn't really have any rules!
Part of the problem is that Google makes it impossible to search for anything other than alphanumerics so you can't search for things like
<SCRIPT> or <?php. So, first question, is there *any* way now that Google rules the world to search for things like this? Moving on, how can one find what *actually* works inside a <SCRIPT> section in HTML? Is it only javascript that really works there in 'most' browsers or are there other possibilities? The other question is how does <?php work at all? I can't find anything that documents how or why it should allow PHP to do things. I'm maybe missing something obvious but given Google's total inability to look for such things doing any sort or searching is a bit difficult. I have O'Reilly books on HTML and PHP but neither of them really addresses how this works. I do realise that <SCRIPT> starts client side scripting so is limited by what's implemented in browsers, however it is at least a 'proper' HTML element. <?xxx seems more of a bodge, is it actually a bodge or is there some smeantic/syntactic logic to it? -- Chris Green _______________________________________________ main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!
On Thu, Feb 04, 2010 at 09:33:57PM +0000, Ian Porter wrote:
The script is a client browser script where as the php is a server side script.
Yes, I realise that, I already run server side PHP and things like that on my apache2 server. I was just trying to find details about the <?php syntax and how it works.
Well if you want to put some PHP code in to a page you open the php tag:
<?php
MY_PHP_CODE_HERE
then close the php tag like so:
?>
When a client browses a page on your web server with these tags in the page the web server see's the tags it processes the code before serving the client the page. This is not a native language of a web server or browser. To have PHP pages hosted on your server you must have the PHP module installed. For Apache you need to download and install the php module and then add it into the httpd.conf file. (These days PHP is often bundles in just not enabled, although that wouldn;t be the case if you downloaded the Apache source and built from scratch). For windows you would need to download PHP, install it somewhere then add it as an extension in you IIS settings and enabled it for processing pages ending in .php.
Another example would be that Microsoft IIS supports ASP which is again a server side scripting language that only runs on the IIS web service if you enabled the ASP extensions.
As far as I am aware you can't have python or perl as a server side scripting language. You may want to look at CGI/Perl scripts however for processing parsed data. You can use Perl in this sense. For example you can have a HTML form submit its data to a Perl script on the server which can then process the parsed information as required (for example, saving it to a file).
So back to the original question, PHP is an extension of your web servers native functionality.
On 04 Feb 23:19, James Bensley wrote:
As far as I am aware you can't have python or perl as a server side scripting language. You may want to look at CGI/Perl scripts however for processing parsed data. You can use Perl in this sense. For example you can have a HTML form submit its data to a Perl script on the server which can then process the parsed information as required (for example, saving it to a file).
Erm, so you've never heard of mod_perl or mod_python, then... though most people use fcgi for perl or wsgi for python, because they're a better seperation and generally better performance.
On 04/02/10 23:19, James Bensley wrote:
When a client browses a page on your web server with these tags in the page the web server see's the tags it processes the code before serving the client the page. This is not a native language of a web server or browser.
I've just scanned this thread so apologies if someone already covered this but it seems to be the main point of confusion.
The web server does *not* interpret <?php tags.
What happens is that the web server is told to pass any file with .php extension (or, if you configure it, any file at all, or any file with .php or .html, or ....).
It is then PHP that scans for <?php .. ?> and processes it. If there are no <?php tags in the script, PHP still parses it, but outputs the file exactly as it reads it.
Therefore there doesn't need to be a "standard" for things like this; the standard is to define which parser parses which files, then let the parser do it's job. With a Perl script, the script is run "as is" so it needs to be a valid perl script in itself, from the first line. PHP starts parsing a file as raw output and only processes the sections it needs to, which means it is possible to do simple tasks in PHP very simply (where you have large sections of raw HTML you don't need to use the script language commands to print/echo/write/whatever the HTML to the output).
So, look in the web browser configuration for the lines which tell it which files to send to (eg) PHP, and that's all you need to understand in this context. You can easily show this: create a file which PHP tags in it and save it as a .html file, then view the page in the browser (and "view source") - you'll see the PHP tags in the code that the browser receives. Re-configure the server to parse .html files with PHP, restart the server, then refresh the browser, and you'll see that the code has gone and PHP has parsed it.
On Fri, Feb 05, 2010 at 09:52:06AM +0000, Mark Rogers wrote:
On 04/02/10 23:19, James Bensley wrote:
When a client browses a page on your web server with these tags in the page the web server see's the tags it processes the code before serving the client the page. This is not a native language of a web server or browser.
I've just scanned this thread so apologies if someone already covered this but it seems to be the main point of confusion.
The web server does *not* interpret <?php tags.
What happens is that the web server is told to pass any file with .php extension (or, if you configure it, any file at all, or any file with .php or .html, or ....).
It is then PHP that scans for <?php .. ?> and processes it. If there are no <?php tags in the script, PHP still parses it, but outputs the file exactly as it reads it.
Aaaaahhhhhhh!!!!!! At last an explanation of how it works, thank you!
Therefore there doesn't need to be a "standard" for things like this; the standard is to define which parser parses which files, then let the parser do it's job. With a Perl script, the script is run "as is" so it needs to be a valid perl script in itself, from the first line. PHP starts parsing a file as raw output and only processes the sections it needs to, which means it is possible to do simple tasks in PHP very simply (where you have large sections of raw HTML you don't need to use the script language commands to print/echo/write/whatever the HTML to the output).
So, look in the web browser configuration for the lines which tell it which files to send to (eg) PHP, and that's all you need to understand in this context. You can easily show this: create a file which PHP tags in it and save it as a .html file, then view the page in the browser (and "view source") - you'll see the PHP tags in the code that the browser receives. Re-configure the server to parse .html files with PHP, restart the server, then refresh the browser, and you'll see that the code has gone and PHP has parsed it.
Yes, all is much clearer now, as you say it's the apache2 configuration files that tell it to fire (for example) .php files at the PHP interpreter. It's the PHP interpreter that recognises the <?php.
On Thu, Feb 04, 2010 at 11:19:21PM +0000, James Bensley wrote:
Well if you want to put some PHP code in to a page you open the php tag:
<?php MY_PHP_CODE_HERE then close the php tag like so: ?>
... and make the page URL end with .php.
When a client browses a page on your web server with these tags in the page the web server see's the tags it processes the code before serving the client the page. This is not a native language of a web server or browser. To have PHP pages hosted on your server you must have the PHP module installed. For Apache you need to download and install the php module and then add it into the httpd.conf file. (These days PHP is often bundles in just not enabled, although that wouldn;t be the case if you downloaded the Apache source and built from scratch). For windows you would need to download PHP, install it somewhere then add it as an extension in you IIS settings and enabled it for processing pages ending in .php.
Another example would be that Microsoft IIS supports ASP which is again a server side scripting language that only runs on the IIS web service if you enabled the ASP extensions.
As far as I am aware you can't have python or perl as a server side scripting language. You may want to look at CGI/Perl scripts however for processing parsed data. You can use Perl in this sense. For example you can have a HTML form submit its data to a Perl script on the server which can then process the parsed information as required (for example, saving it to a file).
So back to the original question, PHP is an extension of your web servers native functionality.
But doesn't really seem to be documented anywhere, the <?php bit that is, everyone just uses it and it works.
Hi,
On 4 February 2010 21:20, Chris G cl@isbd.net wrote:
Moving on, how can one find what *actually* works inside a <SCRIPT> section in HTML? Is it only javascript that really works there in 'most' browsers or are there other possibilities?
I belive it's just javascript. There might be other obscure client-side script languages that are supported though. There's probably something on W3C that lists the possible types of languages.
The other question is how does <?php work at all? I can't find anything that documents how or why it should allow PHP to do things. I'm maybe missing something obvious but given Google's total inability to look for such things doing any sort or searching is a bit difficult.
I'd say this is more a problem of a PEBKAC rather than Google's fault. ;)
I have O'Reilly books on HTML and PHP but neither of them really addresses how this works.
Maybe you're not reading carefully enough? :P
I do realise that <SCRIPT> starts client side scripting so is limited by what's implemented in browsers, ......
PHP is a *server-side* language. It has nothing to do with what is implemented in the browser.
The <?php and <? tags are seen by the web server, passed to the PHP module/library/whatever, which is then what processes the PHP code, does business logic/db or file access/etc and then (often) generates HTML which is passed to the webserver and then sent to the client browser. I think. (I don't pretend to know exactly how this works though, so the above is a probable description of what happens given what I have come across and given that I'm a programmer).
Hopefully that explains things.
Regards, Srdjan
Note before: I have no idea what level of knowledge you have with this stuff some I'm start from the top, sorry if I seem undermining.
OK, first the <script> tag. This tag lets you declare a sub section of your HTML code in which you can use another language. HTML is rather static on its own and so other languages like JavaScript give you the ability to insert some more dynamic and interactive code.
Another language you could use in the <script> tag is VBScript (Visual Basic Script) however this is limited to Windows clients as Visual Basic is a Microsoft language for scripting elements of the Windows environment which can be inserted into a HTML page or HTA (HTML Application). A slightly inaccurate parody would be if you could insert bash script into you bash for the clients browser to interpret along side the HTML. Visual Basic Script, VBScript or VBS is a variation on a full blown high level application language called Visual Basic which is a for writing high level applications within Windows (again another slightly inaccurate parody would be to imagine if you could insert 'PythonScript' directly into your HTML pages giving you a less powerful version of python to work with.
On the to PHP stuff. PHP is a server side language. What does this mean? It means than you can write a HTML page in your favourite text editor and then open it in your favourite browser and it will interpret the result and display a page. You could even throw some JavaScript in there (don't confuse JavaScript with Java!). This can all be done on your desktop.
PHP is a server side language which means you need a web service (like Apache) running serving up your pages like a web server with the PHP extensions/interpreter installed. What this means is that you can write a page in HTML and throw some PHP in. Then when a client browses to mywebserver.com/my_php_page.php on the server, instead of simply parsing the client browser the code of the page to render the server sees that the file has a .php extension and reads and executes the PHP code sending the resulting HTML code of that PHP code execution to the clients browser.
HTH and didn't confuse you more!
On Thu, Feb 04, 2010 at 09:58:41PM +0000, James Bensley wrote:
PHP is a server side language which means you need a web service (like Apache) running serving up your pages like a web server with the PHP extensions/interpreter installed. What this means is that you can write a page in HTML and throw some PHP in. Then when a client browses to mywebserver.com/my_php_page.php on the server, instead of simply parsing the client browser the code of the page to render the server sees that the file has a .php extension and reads and executes the PHP code sending the resulting HTML code of that PHP code execution to the clients browser.
So where is this <?php syntax defined? Is it part of HTML, is it a bodge added by apache or what is it? That's really what I was asking, I (sort of) know the difference between server side and client side stuff (I think I did even say something about <SCRIPT> being client side) and <SCRIPT> is at least 'proper' HTML.
On 04 Feb 23:10, Chris G wrote:
On Thu, Feb 04, 2010 at 09:58:41PM +0000, James Bensley wrote:
PHP is a server side language which means you need a web service (like Apache) running serving up your pages like a web server with the PHP extensions/interpreter installed. What this means is that you can write a page in HTML and throw some PHP in. Then when a client browses to mywebserver.com/my_php_page.php on the server, instead of simply parsing the client browser the code of the page to render the server sees that the file has a .php extension and reads and executes the PHP code sending the resulting HTML code of that PHP code execution to the clients browser.
So where is this <?php syntax defined? Is it part of HTML, is it a bodge added by apache or what is it? That's really what I was asking, I (sort of) know the difference between server side and client side stuff (I think I did even say something about <SCRIPT> being client side) and <SCRIPT> is at least 'proper' HTML.
It's defined in the mod_php spec. It's a language in it's own right. Go read the documentation at http://www.php.net/.
On Thu, Feb 04, 2010 at 09:36:56PM +0000, Srdjan Todorovic wrote:
Hi,
On 4 February 2010 21:20, Chris G cl@isbd.net wrote:
Moving on, how can one find what *actually* works inside a <SCRIPT> section in HTML? Is it only javascript that really works there in 'most' browsers or are there other possibilities?
I belive it's just javascript. There might be other obscure client-side script languages that are supported though. There's probably something on W3C that lists the possible types of languages.
The other question is how does <?php work at all? I can't find anything that documents how or why it should allow PHP to do things. I'm maybe missing something obvious but given Google's total inability to look for such things doing any sort or searching is a bit difficult.
I'd say this is more a problem of a PEBKAC rather than Google's fault. ;)
I have O'Reilly books on HTML and PHP but neither of them really addresses how this works.
Maybe you're not reading carefully enough? :P
I do realise that <SCRIPT> starts client side scripting so is limited by what's implemented in browsers, ......
PHP is a *server-side* language. It has nothing to do with what is implemented in the browser.
Yes, I realise that, though HTML documentation doesn't seem to.
The <?php and <? tags are seen by the web server, passed to the PHP module/library/whatever, which is then what processes the PHP code, does business logic/db or file access/etc and then (often) generates HTML which is passed to the webserver and then sent to the client browser. I think. (I don't pretend to know exactly how this works though, so the above is a probable description of what happens given what I have come across and given that I'm a programmer).
Yes, so is the <?php tag just a bodge that only works with, for example, apache2, or what is it? Are there other tags like this possible, e.g. <?perl or <?python ? If not, why not? (I just like logic to my computer programming!)
On 4 February 2010 23:07, Chris G cl@isbd.net wrote:
On Thu, Feb 04, 2010 at 09:36:56PM +0000, Srdjan Todorovic wrote:
The <?php and <? tags are seen by the web server, passed to the PHP module/library/whatever, which is then what processes the PHP code, does business logic/db or file access/etc and then (often) generates HTML which is passed to the webserver and then sent to the client browser. I think.
Yes, so is the <?php tag just a bodge that only works with, for example, apache2, or what is it? Are there other tags like this possible, e.g. <?perl or <?python ? If not, why not? (I just like logic to my computer programming!)
I would think that <?php and <? is a PHP specific element. You could check by perhaps looking at the PHP source code or PHP developer docs.
Something somewhere would have defined that as the delimiter for the start of PHP code.
I don't think there is a <?python directive. But if you could change Apache source code and if Python could act as CGI, then I can't see why it won't be possible to have <?python. Of course you'd then have to make sure your python is well formatted because the silly language does not use ; and {} ;)
Srdjan
On 04 Feb 23:19, Srdjan Todorovic wrote:
On 4 February 2010 23:07, Chris G cl@isbd.net wrote:
On Thu, Feb 04, 2010 at 09:36:56PM +0000, Srdjan Todorovic wrote:
The <?php and <? tags are seen by the web server, passed to the PHP module/library/whatever, which is then what processes the PHP code, does business logic/db or file access/etc and then (often) generates HTML which is passed to the webserver and then sent to the client browser. I think.
Yes, so is the <?php tag just a bodge that only works with, for example, apache2, or what is it? Are there other tags like this possible, e.g. <?perl or <?python ? If not, why not? (I just like logic to my computer programming!)
I would think that <?php and <? is a PHP specific element. You could check by perhaps looking at the PHP source code or PHP developer docs.
Something somewhere would have defined that as the delimiter for the start of PHP code.
I don't think there is a <?python directive. But if you could change Apache source code and if Python could act as CGI, then I can't see why it won't be possible to have <?python. Of course you'd then have to make sure your python is well formatted because the silly language does not use ; and {} ;)
Correct, there's no <?python directive, because when you tell things that they should be processed by mod_python it interprets the code as *python*, not a bastard mix of html and random scripting.
Also, just because something has syntax that doesn't use ; and {} doesn't mean that it's a silly language, and I'd much rather pick up python code a lot of the time because it's correctly indented, and therefore a hell of a lot easier to read.
I can only assume that you're a fan of write-once languages :P
At Thu, 4 Feb 2010 23:07:36 +0000, Chris G wrote:
The <?php and <? tags are seen by the web server, passed to the PHP module/library/whatever, which is then what processes the PHP code, does business logic/db or file access/etc and then (often) generates HTML which is passed to the webserver and then sent to the client browser. I think. (I don't pretend to know exactly how this works though, so the above is a probable description of what happens given what I have come across and given that I'm a programmer).
Yes, so is the <?php tag just a bodge that only works with, for example, apache2, or what is it? Are there other tags like this possible, e.g. <?perl or <?python ? If not, why not? (I just like logic to my computer programming!)
The pattern of these tags is borrowed from XML processing instructions http://www.w3.org/TR/REC-xml/#sec-pi, which allow XML documents to embed information intended to be passed to the processing application. The most common processing instruction example is the XML declaration which many XML documents include at the top:
_ <?xml version="1.0" encoding="utf-8" ?>
Another one is telling a parsing application to use a particular stylesheet:
_ <?xml-stylesheet href="style.css" type="text/css" ?>
I've used an Python implemented XML template language called Genshi http://genshi.edgewall.org/ in the past which prides itself on its templates being valid (i.e. well formed and validatable against a DTD) XML documents. One of its (admittedly minor) features is that it allows the embedding or verbatim Python code inside a <?python processing instruction, whilst retaining the well formedness of the template document (because arbitrary processing instructions are permitted in XML documents).
On Thu, 2010-02-04 at 21:20 +0000, Chris G wrote:
Moving on, how can one find what *actually* works inside a <SCRIPT> section in HTML? Is it only javascript that really works there in 'most' browsers or are there other possibilities?
It is pretty much just JavaScript. If you are prepared to tie yourself down to Windows and IE you can use VBScript but personally I wouldn't.
The other question is how does <?php work at all? I can't find anything that documents how or why it should allow PHP to do things. I'm maybe missing something obvious but given Google's total inability to look for such things doing any sort or searching is a bit difficult. I have O'Reilly books on HTML and PHP but neither of them really addresses how this works.
I do realise that <SCRIPT> starts client side scripting so is limited by what's implemented in browsers, however it is at least a 'proper' HTML element. <?xxx seems more of a bodge, is it actually a bodge or is there some smeantic/syntactic logic to it?
If you've ever programmed in C this is a bit like working with the pre-processor, i.e. things like #include and #define are not part of the C language (though they later got standardised) but specify a transformation that happens to the C program before the compiler sees it.
Likewise with <?php which specifies a transformation that happens to the file on the server before it hits the user's web browser. The <? was no doubt chosen to avoid the possibility of a clash with anything anyone would want to write in HTML. Starting this marker with a < character means it will not clash with any normal text as that would have < characters converted to the < entity so as to avoid a clash with tags and having ? as the second character as ? means it doesn't clash with any HTML tags as these all start with letters. Interestingly XML has a similar thing. In XML <? starts a 'processing instruction'.
One usually thinks of this kind of hybrid page as embedding code in HTML but in practice what normally happens is that when a user tried to access the page it is converted into code in the language that appears to be embedded in the HTML HTML portions turned into strings and that code is executed. For better performance that compiled version maybe cached. An example of this is JSP where a JSP page gets compiled into a servlet.
Steve.
Please excuse the brief reply but I don't have good access to email from here!
have a look at this web site. http://www.w3schools.com/default.asp
they have tutorials on javascript, html, php, xhtml etc etc. they also appear to be the keepers of the standards!
nev
cl@isbd.net wrote:
I've been trying to find out the rules about embedded scripting in HTML, things like PHP and JavaScript. It seems like it doesn't really have any rules!
Part of the problem is that Google makes it impossible to search for anything other than alphanumerics so you can't search for things like
<SCRIPT> or <?php. So, first question, is there *any* way now that Google rules the world to search for things like this? Moving on, how can one find what *actually* works inside a <SCRIPT> section in HTML? Is it only javascript that really works there in 'most' browsers or are there other possibilities? The other question is how does <?php work at all? I can't find anything that documents how or why it should allow PHP to do things. I'm maybe missing something obvious but given Google's total inability to look for such things doing any sort or searching is a bit difficult. I have O'Reilly books on HTML and PHP but neither of them really addresses how this works. I do realise that <SCRIPT> starts client side scripting so is limited by what's implemented in browsers, however it is at least a 'proper' HTML element. <?xxx seems more of a bodge, is it actually a bodge or is there some smeantic/syntactic logic to it? -- Chris Green _______________________________________________ main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!
Chris G wrote:
/Sorry Chris, forgot to change destination - again.../
I've been trying to find out the rules about embedded scripting in HTML, things like PHP and JavaScript. It seems like it doesn't really have any rules!
Very reasonably-priced book - less than eleven squids, HTML in Easy Steps ( www.ineasysteps.com ) ISBN-10: 1-84078-359-1
I bought the first edition in a charity shop because I waanted some more gen on CSS, and finding it pretty informative, though about ten years out of date, within a week I had ordered and collected the sixth edition. (Not regretted it, either,)
There are chapters about embedding objects, media, Quicktime, Real Player, Flash, scripting, frames and lots, lots more.