Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Using include() in an echo statement

  1. #11
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mwinter
    Why not just use the readfile function and output the content directly?
    Because with readfile you don't have control over flow- if the file exists, it will be passed to client, if not, error will be generated- file_get_contents allows you to silently evaluate "including" (cause its return is content of the file, or FALSE), and manipulating the content received in manners of variable operations (joining, cutting, replacing, grepping, etc...).

    Secondly you can focus on damage control if it's not included for some reason- think of it like "template" loading, where you can still "default" to something.

    That's not exactly nasty, is it, but expected.
    Well, you can trigger a php code accidently, I'd call it nasty

  2. #12
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    PHP Code:
    <?php
    @readfile('somefilethatwontbeexecuted.php') or exit('Sorry an error has occured');
    ?>
    What is so hard about that?

  3. #13
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blm126
    PHP Code:
    <?php
    @readfile('somefilethatwontbeexecuted.php') or exit('Sorry an error has occured');
    ?>
    What is so hard about that?
    Exactly. Both functions generate errors when the specified file cannot be found, those errors can be suppressed in the same way, and the error condition can be detected as both functions return boolean false.

    As for manipulating the contents, the OP didn't suggest that it was necessary, so it's irrelevant. What's the point in loading data into memory only to write it out again? The readfile function should be able to efficiently send it to the output stream as that's its sole purpose.

    Mike

  4. #14
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    LOL, hey- I was just saying that include should be treated with caution, and in readfile you have no control what's output., besides, with file_get_contents you can do, for example, this:
    Code:
    if (file_exists("$pwd/.README")) {
    	$myText = file_get_contents("$pwd/footer.txt");                         
    	$myText = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",   
    		"<a href=\"\\0\">\\0</a>", $myText);
    	$myText = nl2br($myText);
    	echo $myText
    }
    That's the code I'm using to display "README's" for dirs on my http browsable FTP directory (adds <br>'s and turns adresses into links

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •