Jump to content

Recommended Posts

This is probably piece of cake for you guys, but I cannot make it work:

 

I need to replace the text "<table> bla.bla.</table>" in the following code with the contents of the file conditions.html. My aim is to make the code clear, and to put the html-code into the separate file conditions.html rather than just writing it inside the current text area "<table> bla.bla.</table>":

 

define('TEXT_INFORMATION', '<table> bla.bla.</table>');

 

I have tried with

 

define('TEXT_INFORMATION', include(conditions.html);

 

and a number of other variations, but nothing seems to work.

 

Thanks for any help

 

Mogens

Link to comment
https://forums.phpfreaks.com/topic/42021-newbie-question/
Share on other sites

<?php
$replace = file_get_contents('conditions.html');

define('TEXT_INFORMATION', $replace);

?>

 

Note you can use fopen + fread etc. Basically you do not want to include the file, just read the contents and put them into a string. This should do just that.

 

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203771
Share on other sites

Thanks for your fast reply Frost 8) But when pasting this code into my file I get this error message:

 

Warning: file_get_contents(conditions.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/public_html/includes/languages/conditions.php on line 15

 

The file conditions.html exists in the mentioned directory, and with the include command I succeeded earlier in getting the file outputted, however not as it was supposed to  ???

 

Mogens

Link to comment
https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203782
Share on other sites

Well you need to make sure you have the path specified too. If that file is not contained within the directory you are running the script the path needs to be specified.

 

IE:

 

script.php is located in /home/public_html/includes

conditions.html is located in /home/public_html/includes/languages

 

In order for script.php to read from conditions.html you need to do this:

$replace = file_get_contents('/languages/conditions.html');

OR

$replace = file_get_contents('/home/public_html/includes/languages/conditions.html');

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203789
Share on other sites

That's a bit strange. The file conditions.html is located in the exact same directory as the file conditions.php. The latter contains the script, so I should not need to specify the path.

 

If I try this code:

define('TEXT_INFORMATION', include('conditions.html'));

Then the result is that the contents of conditions.html is shown on top of the website when I address conditions.php via the url. This proves that conditions.html exists in the same directory as conditions.php, or?

 

Mogens

Link to comment
https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203816
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.