Php + Htm Cant Work!

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Php + Htm Cant Work!

kakingho
test.php
CODE
<?php

$abc='123';
include 'index.htm';

?>


index.htm
HTML
<table width="200" border="1">
<tr>
<td>$abc</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>

it shows this pic
http://i19.photobucket.com/albums/b190/kakingho/abc.jpg

but i want to show this
http://i19.photobucket.com/albums/b190/kakingho/123.jpg

i want to separate main php codes in php file and main website structure in htm file~
how to do that?!

i dont want to type this in htm file, any other method?? ohmy.gif
HTML
<table width="200" border="1">
<tr>
<td><?PHP $abc; ?></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>

thx~

Notice from BuffaloHELP:
Please limit your picture's width to no more than 640px

 

 

 


Reply

Inspiron
You've actually answered for yourself.

This code
CODE

<td><?PHP $abc; ?></td>

or this code
CODE

<td><?php echo $abc; ?></td>

will work similarly.

Unfortunately, you have to do this to obtain the content of the variable $abc. There are no other ways because HTML cannot take non-HTML codes. The server does not understand $abc and hence treated it as plain text to display on a normal HTML page. Inserting PHP code tags and changing the file type to PHP will print the correct information as they stated the correct scripting.

Likewise you cannot have javascript contents without declaring it's a javascript.
<script language="javascript">

Reply

Spectre
Alternatively, you could simply get the contents of the file, and replace the said string with the variable's value, something like:

CODE
<?php

$abc='123';
echo str_replace('$abc',$abc,file_get_contents('index.htm'));

?>


You may want to check out the Smarty template engine; it's very easy to use and works wonderfully, and operates on a similar premises to this. You simply add the variable in the template along the lines of {$VARIABLE}, and Smarty automatically replaces it with the assigned value ($smarty->assign('VARIABLE','value');) when displaying it.

Anyway, PHP is not going to process any data outside of the <? ?> tags (usually <?php ?>, but not always). Which means that you are going to explicitly instruct it to output the said variable.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : php htm


    Looking for php, htm, work

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for php, htm, work

*MORE FROM TRAP17.COM*
advertisement



Php + Htm Cant Work!



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE