Most of the time, you can't. You must first change the HTML file over to a PHP file by changing it's extention from .html to .php Then to add the php code, you just wrap it in PHP tags within your original code. PHP tags are either <? ?> or
<?php
?>
depending on server settings.
Example...
Original file (testfile.html)
<html><head><title>Test Page</title></head> <body> <h2>Welcome to my test page</h2> </body> </html>
Add Php to it and rename it (testfile.php)
<html><head><title>Test Page</title></head> <body> <h2>Welcome to my test page</h2> <p>We have detected you are accessing this page from <? echo $_SERVER['REMOTE_ADDR']; ?> </p> </body> </html>
Some notes:
1. Technically it is possible to use the orignal .html file for PHP code if your server is set up to do so. Most are not though.
2. For the example I used, just sending a variable to the output, you can use the following shortcut instead
by the way, if I delete .htaccess file, I can not open my page, always ask "............... save file?",
can anybody tell me why, there was not .htaccess file several weeks ago, my website even runed good.
Acturelly, I think the codes are correct, I saved codes as PHP file, uploaded to server, they did work, but if I insert codes into HTML file, they do not work. I think maybe server does support it.
Line 35 to Line 42
if ( is_array($arr_xml) ) {
echo "\n
Greg K posted this at 15:17 — 21st January 2007.
He has: 1,667 posts
Joined: Nov 2003
Most of the time, you can't. You must first change the HTML file over to a PHP file by changing it's extention from .html to .php Then to add the php code, you just wrap it in PHP tags within your original code. PHP tags are either <? ?> or
<?php
?>
depending on server settings.
Example...
Original file (testfile.html)
<html><head><title>Test Page</title></head><body>
<h2>Welcome to my test page</h2>
</body>
</html>
Add Php to it and rename it (testfile.php)
<html><head><title>Test Page</title></head><body>
<h2>Welcome to my test page</h2>
<p>We have detected you are accessing this page from
<?
echo $_SERVER['REMOTE_ADDR'];
?>
</p>
</body>
</html>
Some notes:
1. Technically it is possible to use the orignal .html file for PHP code if your server is set up to do so. Most are not though.
2. For the example I used, just sending a variable to the output, you can use the following shortcut instead
<?php= echo $_SERVER['REMOTE_ADDR']
?>
-Greg
[This space intentionally left blank]
Cool Geek Supplies: www.ThinkGeek.com
rcajht posted this at 16:05 — 21st January 2007.
They have: 12 posts
Joined: Jan 2007
Thanks Greg, I will try your method Monday.
rcajht posted this at 19:35 — 22nd January 2007.
They have: 12 posts
Joined: Jan 2007
I tried your code, it indeed works, (shows my IP address), but after I copied Ads codes I got from other website, I got:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in line 39,
line39:
".$arr_xml['Text'][$i]." ".$arr_xml['AfterText'][$i]."
\n";
do I need to modify .htaccess file?
by the way, if I delete .htaccess file, I can not open my page, always ask "............... save file?",
can anybody tell me why, there was not .htaccess file several weeks ago, my website even runed good.
Stock Trading | Webmaster HelpIsland
Busy posted this at 21:11 — 22nd January 2007.
He has: 6,157 posts
Joined: May 2001
Whats on line 37 and 38 ?
the line should either start with echo (or print) or be assigned to a variable: $adcode = "....
<?bhb if(broken){ echo("It wasn't me
"); } ?>
Learn HTML the ez way - EzHTML.net
Some people are like slinkies, they dont really serve any purpose but they still bring a smile to your face when you push them down the stairs ...
rcajht posted this at 21:32 — 22nd January 2007.
They have: 12 posts
Joined: Jan 2007
Acturelly, I think the codes are correct, I saved codes as PHP file, uploaded to server, they did work, but if I insert codes into HTML file, they do not work. I think maybe server does support it.
Line 35 to Line 42
if ( is_array($arr_xml) ) {
echo "\n
n";- ".$arr_xml['BeforeText'][$i]."
for ($i = 0; $i < count($arr_xml['URL']); $i++) {
echo "
".$arr_xml['Text'][$i]." ".$arr_xml['AfterText'][$i]."
\n";
}
echo "
";
}
Stock Trading | Webmaster HelpIsland