mlu Posted March 9, 2007 Share Posted March 9, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/42021-newbie-question/ Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203771 Share on other sites More sharing options...
mlu Posted March 9, 2007 Author Share Posted March 9, 2007 Thanks for your fast reply Frost 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 Quote Link to comment https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203782 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203789 Share on other sites More sharing options...
mlu Posted March 9, 2007 Author Share Posted March 9, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203816 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Sometimes includes are weird. I would try the file_get_contents with the whole location to the file in the string. If it is in '/home/public_html/includes/languages/conditions.html' use that. See what that produces. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203823 Share on other sites More sharing options...
mlu Posted March 9, 2007 Author Share Posted March 9, 2007 Bingo - a fully qualified path did the trick Thanks a lot for your help FrosT - this really will help me clean up my code and make it a whole lot easier to maintain it in the future! Cheers / Mogens Quote Link to comment https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203842 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Yea, I am still trying to figure out the whole path thing. It is a pain in my butt at times. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42021-newbie-question/#findComment-203846 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.