Jump to content
xisto Community
Sign in to follow this  
kakingho

Php + Htm Cant Work!

Recommended Posts

test.php

<?php$abc='123';include 'index.htm';?>


index.htm
<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?? :lol:

<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

Share this post


Link to post
Share on other sites

You've actually answered for yourself.

This code

<td><?PHP $abc; ?></td>
or this 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">

Share this post


Link to post
Share on other sites

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

 

<?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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.