hey im trying to include a text file for an ajax chat room but its printing the content from the text file i dont want it to echo / print require_once ROOT_DIR.'/chat/w.php'; require ROOT_DIR.'/chat/chat.txt'; PHP: i dont want to rename it to php because the ajax is built on the text file Please help
i thought that <?php include('textfile.txt'); ?> PHP: would work without echoing or printing it. but im not sure. :S
nope it dont work and all thats it the text files is well plain texts thats used to pull the chat contents ie Robert | test<br> Robert | test<br> ? | test<br> hello | dc sdf df <br> But its being echoed at the top of the page aswell in the chat i only want the ajax from the chat to pull the text not the index its self but it must be included in the index for the chat to find it
You could always put it in script tags and use that as a variable. <script> var read = new XMLHttpRequest(); var sURL = "text.txt"; read.open("GET",sURL,false); read.send(null) var text= read.responseText; </script> Code (markup): maybe not the best solution but it works. put the text in text.txt and whenever you need it just use the variable "text". If you need it in other directories, just use an absolute path such as "var sURL = 'http://www.example.com/text.txt'"
Melol2 has a good answer to it. Or you could use the function file_get_contents($url); if you need it to be in your PHP.
$string = get_include_contents('somefile.php'); function get_include_contents($filename) { if (is_file($filename)) { ob_start(); include $filename; $contents = ob_get_contents(); ob_end_clean(); return $contents; } return false; } PHP: Any good?