Mike12345

msg:3952248 | 2:02 pm on Jul 14, 2009 (gmt 0) |
I think eval [us2.php.net] will help.
|
jharker1987

msg:3952272 | 3:13 pm on Jul 14, 2009 (gmt 0) |
thanks for your post. i have implemented this but found it to be painfully slow! i think ill try a different route
|
jharker1987

msg:3952278 | 3:22 pm on Jul 14, 2009 (gmt 0) |
here is the code while(!feof($file)) { eval("" . fgets($file) . ";"); } fclose($file);
does anybody know why it is so slow?
|
coopster

msg:3952282 | 3:30 pm on Jul 14, 2009 (gmt 0) |
Welcome to WebmasterWorld, jharker1987. Use include instead of fopen in your function. Check to see if the file exists and if so, include it. The included code will be parsed.
|
jharker1987

msg:3952327 | 4:14 pm on Jul 14, 2009 (gmt 0) |
ok this is beginning to work now. here is what ive got $file=fopen("articles/" . $id . "/p" . $id . "_php.php","r") or exit("<p>Unable to get the selected article.</p>"); $str = ""; while(!feof($file)) { $str .= fgets($file) . ";"; } fclose($file); eval($str); $file=fopen("articles/" . $id . "/p" . $id . ".php","r") or exit("<p>Unable to get the selected article.</p>"); while(!feof($file)) { $line = "". fgets($file); if (strlen(strstr($line,"<?php"))>0) { eval ($line . ";"); } else { echo("" . $line); } } fclose($file);
the first loop appears to work correctly. the second loop is for the actual body of the html code. within, there are little php snippets, here is an example: <div class="curlycontainer"> <div class="innerdiv"> <?php GetCode3();?> </div> </div>
so the second loop looks for the php code, if found, does eval otherwise does echo. although it seems to work kinda (there is no php code in the source of the document) just blank spaces appear where the result should be. where am i going wrong?
|
andrewsmd

msg:3952479 | 7:37 pm on Jul 14, 2009 (gmt 0) |
Try this I actually echoed the contents of another php file. $file = file("yourFileHere.extension"); foreach($file as $i){ echo(htmlentities($i)."<br>"); }//foreach [edited by: andrewsmd at 7:42 pm (utc) on July 14, 2009]
|
andrewsmd

msg:3952481 | 7:41 pm on Jul 14, 2009 (gmt 0) |
I just noticed in your original code if you put function GetArticleSource($id) { $file=fopen("articles/" . $id . "/p1.php","r") or exit("<p>Unable to get the selected article.</p>"); while(!feof($file)) { echo htmlentities(fgets($file)); } fclose($file); } I think that should also work. Unless it wasn't working for some other reason. But reading the way in my previous code is a lot easier as long as you can base your output on carriage returns within the file. Thats how the file() function works. It creates an array with each line as a separate value. Let me know if you need anymore help, I had to work alot with most of the file functions at my previous job.
|
|