PDA

View Full Version : How do I insert PHP into HTML page?



MrRSMan
07-22-2007, 11:55 AM
Hi. Before I start, I am a TOTAL newbie at PHP. Infact, I'm not even 100% sure that the code below IS PHP.

Anyway, I have the following code, as you can see. All I need to know is how to insert it into an HTML page!

Also, could someone just run through this an check for any errors please, if at all possible?

;RuneScape Stats script by Daveoh
on 1:LOAD:{
var %i = 1
while ($gettok(%rsuserlist,%i,32)) {
.timerrsstats.daily. $+ $v1 00:01 0 1 rsstats $v1 nochan day
.timerrsstats.hour. $+ $v1 0 3600 rsstats $v1 nochan hour
.timerrsstats.update. $+ $v1 1 $r(1,60) rsstats $v1 nochan hour
inc %i
} }
on 1:UNLOAD:{
.timerrsstats* off
}
on *:TEXT:!rsstats*:#:{ if (%rsstats.spam) halt | set -u5 %rsstats.spam 1
if (!$2) { msg $chan !rsstats usage: !rsstats [user] }
else rsstats $2 $chan
}
alias rsstats {
set %rsuser $1
set %rsop $3
set %rschan $2
if (!$sock(rsstats)) sockopen rsstats hiscore-web.runescape.com 80
else .timer 1 60 rsstats $1-
}
alias -l htmlfree {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&,$chr(9))
return %x
}
on *:SOCKOPEN:rsstats:{
sockwrite -n $sockname GET /lang/en/aff/runescape/hiscorepersonal.ws?user1= $+ %rsuser HTTP/1.1
sockwrite -n $sockname Host: hiscore-web.runescape.com
sockwrite -n $sockname Connection: close
sockwrite -n $sockname $crlf
}
on *:SOCKREAD:rsstats:{
if ($sockerr > 0) return
sockread %temp
if ($sockbr == 0) return
if (%i > 1) { dec %i }
elseif (%i == 1) {
if (*does not feature* iswm %temp) { if (%rschan != nochan) msg $v1 $gettok(%temp,1,46) | .timer*. $+ %rsuser off | goto unset }
set %rsuser. $+ %rsuser $+ .curexp $htmlfree(%temp)
if (!%rsuser. $+ %rsuser $+ .hourexp) || (%rsop == hour) set %rsuser. $+ %rsuser $+ .hourexp $htmlfree(%temp)
if (!%rsuser. $+ %rsuser $+ .dayexp) || (%rsop == day) set %rsuser. $+ %rsuser $+ .dayexp $htmlfree(%temp)
if (!$istok(%rsuserlist,%rsuser,32)) set %rsuserlist %rsuserlist %rsuser
if (!$timer(rsstats.daily. $+ %rsuser)) .timerrsstats.daily. $+ %rsuser 00:01 0 1 rsstats %rsuser nochan day
if (!$timer(rsstats.hour. $+ %rsuser)) .timerrsstats.hour. $+ %rsuser 0 3600 rsstats %rsuser nochan hour
if (%rschan != nochan) {
msg $v1 Current XP for %rsuser = $eval($+(%,rsuser.,%rsuser,.curexp),2) $+ , earned in last hour = $regsubex($calc($remove($eval($+(%,rsuser.,%rsuser,.curexp),2),$chr(44)) - $remove($eval($+(%,rsuser.,%rsuser,.hourexp),2),$chr(44))),/(?<=\d)(?=(\d{3})+$)/g,$chr(44)) $+ , in last day = $regsubex($calc($remove($eval($+(%,rsuser.,%rsuser,.curexp),2),$chr(44)) - $remove($eval($+(%,rsuser.,%rsuser,.dayexp),2),$chr(44))),/(?<=\d)(?=(\d{3})+$)/g,$chr(44))
}
:unset
sockclose rsstats
unset %rsuser | unset %i | unset %rsop | unset %rschan | unset %temp
}
if (Overall == %temp) { set %i 4 }
}

I'm sure this is a very simple question is you know PHP, so I will thank you in advance =).

MrRSMan.

Twey
07-22-2007, 12:52 PM
That's not PHP. I've no idea what it is.

djr33
07-22-2007, 02:38 PM
That code looks like complete nonsense to me. Certainly not PHP. First thought was it might be ASP, but it's too weird for that. There are some other options, but if Twey doesn't know, that's just strange.

Where did you get the code, and what purpose does it serve? I'm almost positive there's a better way.


Now, to insert PHP into an html page, you need the page to have a .php extension instead of .html (this will not change how the page functions, at all, but be sure to update links to it, etc.), and enclose the code in PHP tags: <?php ...CODE HERE... ?>

Following the same logic, whatever that language is, if it is valid, would require tags and an extension... probably. So, if the language is ABC, then there's some chance it would be a ".abc" extension and "<?abc ?>". ...Or something like that. More likely, though, the tags would be <&#37; %>, since that is used by several languages.
But, really, this is all just random guesses.

Twey
07-22-2007, 02:43 PM
After a quick Google, I think that's mIRC script.

djr33
07-22-2007, 02:56 PM
In which case what I said above is probably irrelevant, and I'm confused as to why you would want to use this script.
My best guess is that you would want to embed an object of some sort, and this script would go in an external file.

MrRSMan
07-22-2007, 03:45 PM
The code is supposed to be a high-score lookup for the game RuneScape (http://hiscore.runescape.com/index.ws).

Is there a better way to acomplish this?

kobo1d
07-22-2007, 03:59 PM
after a quick google, i found this ->

http://runearchives.net/derrick/?p=6

its php... :)


btw.: you cant add php to html.. but other way round.. u can add html to a php page..
so its better to rename your script from maybe index.htm to index.php ..
now u can work with html and php on 1 page..

just place php code inside the php tags -> <?php ..CODE.. ?>
everything outside will be handled as normal html..

djr33
07-22-2007, 04:18 PM
Huh?

You can add PHP to html all you want. Just, as you said, put it in PHP tags...

MrRSMan
07-22-2007, 04:20 PM
OK, thank you everyone =)

If you have any other ideas, I would really appreciate them!

MrRSMan
07-22-2007, 04:23 PM
So the page would look like this? index.PHP

<head>text</head>

<body>more text

<?php

Code here...

?>

More text</body>

Twey
07-22-2007, 04:34 PM
Huh?

You can add PHP to html all you want. Just, as you said, put it in PHP tags...S/he's right... technically you're adding HTML to PHP, since the whole thing is sent through the PHP parser.

djr33
07-22-2007, 04:39 PM
It's a page of text.

1+2 gives the same results as 2+1, unrelated to which is done first or which is being added to the other.

<html></html> --> <html><?php echo "<body>"; ?></html>
No?

It's just an issue of semantics, though, unrelated to the code anyway.

Twey
07-22-2007, 05:16 PM
<html></html> --> <html><?php echo "<body>"; ?></html>
No?Not necessarily. In fact, I'd say even the <html></html> is technically PHP if it's being sent through the parser; the fact that the PHP parser decides to output this part of the code verbatim is irrelevant.

djr33
07-22-2007, 06:57 PM
You have html page. Then you rename that page whatever.php. And that's all PHP code?
Whether or not you want to argue that, it doesn't really hold up in any practical situation. If you're using PHP, you still need to know html, right?

alexjewell
07-22-2007, 07:05 PM
Ah, but what about other file types PHP can send out? CSS, JavaScript, images...they all run through the PHP parser and gives the browser something IT can work with...

I'm with Twey, here. If the file is a PHP file, everything in it is technically PHP.

Twey
07-22-2007, 07:14 PM
If you're using PHP, you still need to know html, right?Only if you want to output HTML. Not necessarily even then, actually, since there are DOM builders and things that allow one to generate an HTML document without knowing HTML, in much the same way that GD allows one to generate a GIF image without knowing the GIF format.

djr33
07-22-2007, 07:17 PM
So... Javascript and CSS are also PHP?
JPGs are as well, if they are served through PHP?


This argument could go on forever, just depending on how you want to look at it.

Is the word "Pi&#241;ata" Spanish or English when used in English, such as "I just hit a pi&#241;ata."?
It's Spanish. But it's used in English. It's also an acceptable word in English, without a substitute. So it must be English. But it's Spanish. It's PHP. It's HTML. It's.... a pi&#241;ata. :p

It's worth knowing that the text is sent through the parser, but only to the extent that you know which portions are actually parsed as PHP and which are not (and what happens to those sections that are). Aside from that, all that matters is that you use the same html as you would have in the first place. Certainly nothing to do with PHP.

On top of that, there's a weird generalization being made by this. PHP code and that-which-is-parsed-as-PHP are two separate things.

There is HTML markup and PHP code on a page, and both are passed through the PHP parser. Each is still its original form, yet they are, yes, passed through the parser. In the same sense, there could be PHP code and HTML markup on a page which is not (either by accident, or perhaps as an example of PHP coding) parsed as PHP at any point. Does that mean that the PHP code is HTML? Sure, it's shown as HTML, but the code itself is still PHP.

If you dump water on a sponge, then it's a sponge... it's intended use. But if you dump water on a rock, that doesn't magically make it a sponge. Sure, it had water dumped on it, so it became a thing-that-has-water-dumped-on-it, but it's still not a sponge...

Considering anything on the page as PHP is ridiculous and vague as things start to lose their meanings. If you were to accidentally parse ASP as PHP, then you're claiming that it is then PHP?

HTML and PHP can exist on the same page, and the difference is when they are interpreted. The PHP parser takes all PHP, and transforms it, but not the HTML, into a final state, which is no longer PHP, but plain text, usually HTML. This is then sent on to the browser, as HTML. The browser then interprets the HTML and displays it.



*Note that in some cases, HTML in this post could/should be expanded to DHTML in general, though it's not too important for the point.



EDIT: In response to your latest post, Twey:
Sure. You can use PHP for different output, but we're talking about a page that has mixed PHP and HTML at the moment. That's irrelevant (and the same argument could occur over PHP generating anything, such as MySQL data).
As for templates/functions in use by PHP to generate html, that may be true, but, again, this IS PHP code, rather than plain HTML on the page. I'm not talking about a page that starts with <?php and ends with ?>, with no breaks to the parsed segment, but a page that has some HTML and some PHP included as well.


EDIT 2: Perspective:
I think the main issue here is how you are looking at the situation.
As the server, it is certainly PHP, and must be parsed as such. The act of not parsing specific segments is part of parsing. So, yes, in a way the HTML is treated as PHP.
However, as the programmer/coder, they are very different things, with the HTML written differently than the PHP.
Perhaps this is partly due to the fact that you're more in touch with how the server actually processes than I am, to a crazy degree (not to say bad... it's useful, and amusing;)), so you're looking at it from this angle.

Twey
07-22-2007, 08:19 PM
Is the word "Pi&#241;ata" Spanish or English when used in English, such as "I just hit a pi&#241;ata."?
It's Spanish. But it's used in English. It's also an acceptable word in English, without a substitute. So it must be English. But it's Spanish. It's PHP. It's HTML. It's.... a pi&#241;ata. :pIt's Spanish... the techical term for it is a "loanword." Language definitions are unclear, though... the boundary between a loanword and a native word is as the boundaries between two languages themselves.
On top of that, there's a weird generalization being made by this. PHP code and that-which-is-parsed-as-PHP are two separate things.Not really. They're both just binary data, in the end, like languages are just sounds or marks on paper.
There is HTML markup and PHP code on a page, and both are passed through the PHP parser. Each is still its original form, yet they are, yes, passed through the parser. In the same sense, there could be PHP code and HTML markup on a page which is not (either by accident, or perhaps as an example of PHP coding) parsed as PHP at any point. Does that mean that the PHP code is HTML? Sure, it's shown as HTML, but the code itself is still PHP.No, it's PHP, since it was interpreted by the PHP parser.
If you dump water on a sponge, then it's a sponge... it's intended use. But if you dump water on a rock, that doesn't magically make it a sponge. Sure, it had water dumped on it, so it became a thing-that-has-water-dumped-on-it, but it's still not a sponge...If it was intended to be used as a sponge, then yes, it's a very poor sponge :)
Considering anything on the page as PHP is ridiculous and vague as things start to lose their meanings. If you were to accidentally parse ASP as PHP, then you're claiming that it is then PHP?Invalid PHP, yes.
HTML and PHP can exist on the same page, and the difference is when they are interpreted. The PHP parser takes all PHP, and transforms it, but not the HTML, into a final state, which is no longer PHP, but plain text, usually HTML. This is then sent on to the browser, as HTML. The browser then interprets the HTML and displays it.I'd be inclined to say that the HTML is also transformed -- just into the same HTML that it was in the first place. It's kind of like ROT26 encryption. Movement and transformation are the same thing for electronic and neural data, after all: the electrons of one moment aren't the exact same electrons of the moment before.

djr33
07-23-2007, 12:30 AM
Then how do you define the chunks that I say are HTML as different from the chunks that I say are PHP? Surely there is a difference, and one that can easily be seen. "HTML parsed as PHP" and "PHP parsed as PHP"? That still means one is PHP and the other is HTML. Perhaps "HTML-like PHP" and "PHP-like PHP"? :p

Twey
07-23-2007, 01:08 AM
Heh, ah, you haven't been reading my posts properly :p Since the only way to tell one from the other is by the way they're interpreted, the interpreter defines which is which. The PHP interpreter only sees PHP (thus, it's a PHP interpreter) because it's a machine. Humans are capable of drawing a line between HTML and PHP based on the semantics and patterns of each -- thus, to a human examining the code, there is indeed a difference between the "HTML" portions and the "PHP" portions, and a string such as:
print "<html>";is both PHP and HTML, depending on how the examiner is seeing it: if the examiner notes it only as a string that the PHP will output, then it's PHP; if the examiner attempts to work out the final HTML document that the PHP will generate, for example, and takes it in context with the rest of the HTML document, it's HTML.

However, it's silly to attempt to define such things on so ambiguous a measure, so it's wisest to take it at the parser's value (the parser is, after all, the last observer to interpret the code) and say that it's all PHP.

MrRSMan
07-23-2007, 08:56 AM
I have been reading all of your posts, and I must say, they're very interesting =)...a good introduction for me to PHP I guess...or maybe, thinking about it, it's not...

Anyway, thanks to all of you who have helped =)

MrRSMan.

Twey
07-23-2007, 01:02 PM
a good introduction for me to PHP I guess...or maybe, thinking about it, it's not...No, it's actually nothing to do with PHP, it's more of a philosophical conversation and can be applied to any language or any form of data that will be interpreted :)

djr33
07-23-2007, 01:17 PM
Though it is good to have an idea about some of this, so you know how PHP works.
Many people new to PHP take a long time to understand things like the fact that PHP is generated before any output, so it won't work while the page is running.
Understanding that type of thing (which it seems like you do) is really the most important part of using PHP. From there, it's just memorizing functions and getting used to how to best write a functional page by combining them.

MrRSMan
07-23-2007, 04:21 PM
Hmm...I've just printed out a 50-page tutorial on PHP, which I'll plough through in the next few day...hopefully it won't be too confusin =)

desaitejas
03-20-2009, 08:56 AM
after a quick google, i found this ->

http://runearchives.net/derrick/?p=6

its php... :)


btw.: you cant add php to html.. but other way round.. u can add html to a php page..
so its better to rename your script from maybe index.htm to index.php ..
now u can work with html and php on 1 page..

just place php code inside the php tags -> <?php ..CODE.. ?>
everything outside will be handled as normal html..
Hi
This link is not working.

IN btw..
Im trying to insert Jquery in PHP file but somehow its not wrking..
Need some help