-2

Here is my HTML and I call external PHP

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>
<script src="index.php"></script>
<p>My first paragraph.</p>

</body>
</html>

and my PHP Script

<?
$strFileName = "poom.bis";
$objFopen = fopen($strFileName, 'r');
if ($objFopen) {
    while (!feof($objFopen)) {
        $file = fgets($objFopen, 4096);
//        echo $file;
        echo "document.writeln('$file'+);";
    }
    fclose($objFopen);
}

$test = "hello world";

echo "document.writeln(
    '<ul>'+
        '<li>.$test.</li>'+
        '<li>test2</li>'+
        '<li>test3</li>'+
    '</ul>'
    );";

?>

It error when using document.write more than one time

What should I do to solve this problem

Please Advice

PS. use echo "document.writeln('$file'+);"; for one time there is no error and show a result

Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96
  • 11
    Bottom one is `writeIN`, not `writeLN`. Typo. – BlitZ May 03 '13 at 08:12
  • 3
    So instead of writting output in the server-side, you send the instruction to write output and the output itself to the client-side? Wouldn't it be easier just to `echo` everything without `document.write`? – package May 03 '13 at 08:16
  • 1
    I wonder why everyone that gets an error considers that the error message is not relevant to his problem. – Álvaro González May 03 '13 at 08:18
  • echo won't make a result appear @package – Jongz Puangput May 03 '13 at 08:23
  • and event I use writeln in still error and It's just wrong typing in the question not in my code @CORRUPT – Jongz Puangput May 03 '13 at 08:24
  • 1
    @JongzPuangput So you typed the entire code here :O – Mr. Alien May 03 '13 at 08:26
  • well always copy and past your code we need your exact code. show us the error message. anyway you know that everything you write with `document.writeln` is not visible to search engines? so instad of `` you should change your document containing this to an php document and do an `include` there and use `echo` – t.niese May 03 '13 at 08:28
  • You must use `script type="javascript"` before using `document.write` – conquistador May 03 '13 at 08:28
  • Read this thread, too: [What are alternatives to document.write?](http://stackoverflow.com/questions/4537963/javascript-what-are-alternatives-to-document-write) – olleolleolle May 03 '13 at 08:32

2 Answers2

0

First error: your line

echo "document.writeln('$file'+);";

should be

echo "document.writeln('$file');";

(without the plus sign). Also make sure that the file poom.bis doesn't contain a newline, not even at the end. If it does, you have to strip them away (trim()).

Second error was (until you edited it) the use of document.writeIn (which doesn't exist) instead of document.writeln (which does).

Tested and it works.

Also, while I'm at it, since you asked for advice how to solve this problem: look at your browser's error console and try to debug it.

Carsten
  • 17,991
  • 4
  • 48
  • 53
-1
echo '<script>document.writeln(';
echo '"<ul><li>test1</li><li>test2</li><li>test3</li></ul>"';
echo ');</script>';
;
conquistador
  • 673
  • 3
  • 11
  • 35
  • If you re-read the question carefully, you will see that the PHP file is included as a script file: ``. – Carsten May 03 '13 at 08:39
  • Yes you have, but that's not what I meant. Let me try to explain again: The OP has posted 2 code samples, coming from 2 different files. In the first one, the HTML file, you see that the second one (the PHP file) is included via a ` – Carsten May 03 '13 at 08:58