php-general Digest 26 Sep 2009 15:22:57 -0000 Issue 6359 Topics (messages 298360 through 298364):
Re: How to take output from an include, and embed it into a variable?] 298360 by: Carl Furst 298361 by: Robert Cummings Re: Web Site Directory Layout 298362 by: Ashley Sheridan 298363 by: ×× ××× ×× ×× nl2br() question 298364 by: tedd Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net ----------------------------------------------------------------------
--- Begin Message ---You mean like this ? <?$file string = file_get_contents(urlencode($file_path)); <http://us3.php.net/manual/en/function.file-get-contents.php>$result = eval($file_string); ?>Well I see a few problems with this. One is that scope is not lexical. In other words if $foo exists somewhere in the script and $foo also exists in $file_string then $foo will retain the value it was set to in $file_string. That could lead to some debugging hell. Also, you would have to collect the output and manually return it which means you would have to keep an output cache which means you could only use scripts that cached output and returned them explicitly. However, the flip side is you could have a buffer declared in the local scope that collects the output of $file_string and then put that in the message, but that is not the same as:$foo = include $bar; # this is, of course, impossible Geert Tapperwijn wrote:Can't you just use the eval <http://nl2.php.net/eval> function, and parse the code from the include file in it?.. or is there something I'm missing here?2009/9/25 Carl Furst <cfu...@intracommunities.org <mailto:cfu...@intracommunities.org>>Jim Lucas wrote: Ashley Sheridan wrote:On Wed, 2009-09-23 at 07:36 -0700, Jim Lucas wrote:Mert Oztekin wrote:Output buffering will do it. Also I am not sure but did you try retrieving content with fopen() ? Something like $file = 'invoicetable_bottom.php'; fopen("http://yoursite.com/folder/$file","r"); http://tr.php.net/function.fopen worth trying. Easier than output bufferingThis would not work. fopen would open the file for read. What you would be reading is the actual source of the document. Not the data the script would output when ran. The ob_* functions are the only way that I know of to do what you are asking-----Original Message----- From: Puiu Hrenciuc [mailto:hp...@xentra.ro <mailto:hp...@xentra.ro>] Sent: Wednesday, September 23, 2009 1:36 PM To: php-gene...@lists.php.net <mailto:php-gene...@lists.php.net> Subject: [PHP] Re: How to take output from an include, and embed it into a variable? Hi, The simplest way (actually the single way I know :) ) would be to capture the output using output buffering functions, something like this: // start output buffering ob_start(); // include the file that generates the HTML (or whatever content) include "...."; // get output buffer content $output=ob_get_contents(); // clean output buffer and stop buffering ob_end_clean(); // the content generated in the included file is now in $output variable // use it as you consider fit ......... Regards, Puiu Rob Gould wrote:I have an invoice table that is drawn on a number of pages, so I have all the logic in an include-file like this: include "invoicetable_bottom.php"; However, now I'm needing to take the output from that include file and pass it as an email. To do that, I need to somehow take the output from this include file and get it into a variable somehow. Is there a simple way to do this? Something like: $emailtcontent = include "invoicetable_bottom.php"?-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpThat's just crazy talk. If you use fopen on a web URL, then it will always return the output the script generates. That's how http works!Sorry, my bad. Ash is correct, the method that is suggested will work. But you will need to enable options in your php.ini that are not on by default for security reasons, plus as Ben points out, you will need to filter out the scruff that is generated to capture just the data output from your include. Mind you that all of this also requires that the file that you are including is accessible via the web. It could be in a folder that is not web accessible. Sorry for the initial confusion!Thanks, Ash http://www.ashleysheridan.co.ukDo you have php configured to compile files? Why not just backtick the php -f command?? <? $cmd = *escapeshellcmd*("/full/path/to/php -f $file"); $email_output = `$cmd`; # do something with $email_output ?> Seems easier than a whole http call.. can be risky if the $file variable can be set by user input (big no no), but other than that.. seeems the simplest.-- PHP General Mailing List (http://www.php.net/)To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---Carl Furst wrote:You mean like this ? <?$file string = file_get_contents(urlencode($file_path)); <http://us3.php.net/manual/en/function.file-get-contents.php>$result = eval($file_string); ?>Well I see a few problems with this. One is that scope is not lexical. In other words if $foo exists somewhere in the script and $foo also exists in $file_string then $foo will retain the value it was set to in $file_string. That could lead to some debugging hell. Also, you would have to collect the output and manually return it which means you would have to keep an output cache which means you could only use scripts that cached output and returned them explicitly. However, the flip side is you could have a buffer declared in the local scope that collects the output of $file_string and then put that in the message, but that is not the same as:$foo = include $bar; # this is, of course, impossibleIf you want the include to have it's own variable scope then wrap it with a function. If you want to assign the resulting value via a single call then wrap it in a function. Fortunately both of these combined require one thing... wrap it in a function.<?php function eval_include( $path ) { ob_start(); include( $path ); $result = ob_get_contents(); ob_end_clean(); return $result; } $foo = eval_include( $bar ); ?> Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---On Fri, 2009-09-25 at 22:26 -0400, Robert Cummings wrote: > Caner Bulut wrote: > > Hi All, > > > > Is there a stable or standart directory layout for PHP project (like web > > sites)?. > > > > Example; > > > > index.php > > img/ > > css/ > > js/ > > lib/ > > doc/ > > tools/ > > > > Thanks. > > There's no standard. My advice is to use easily identifiable names. The > above are quite obbvious. My own preference though is to not shorten > names. For instance, I would use the following in place of what you have > provided as examples: > > index.php > images/ > css/ > javascript/ > lib/ > documents/ > tools/ > > That's just personal preference though :) > > Cheers, > Rob. > -- > http://www.interjinn.com > Application and Templating Framework for PHP > I tend to usually go with the following, using what fits with the project: index.php styles/ images/ scripts/ includes/ sometimes I might add directories where it makes sense to, other times I'll compartmentalise the existing directories further. There's not any standard, but I think if you yourself decide on some sort of convention you will use that makes sense to you, it makes things a lot easier in the long run. Thanks, Ash http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---There is no standard for that - Its your choice, I usually use something like index.php configuration.php template/ template/NAME/template.html template/NAME/template.css template/NAME/images/ .... modules/ modules/connection/MySQL.php etc. On Sat, Sep 26, 2009 at 1:50 AM, Caner Bulut <caner...@gmail.com> wrote: > Hi All, > > > > Is there a stable or standart directory layout for PHP project (like web > sites)?. > > > > Example; > > > > index.php > > img/ > > css/ > > js/ > > lib/ > > doc/ > > tools/ > > > > Thanks. > > > > > > -- Use ROT26 for best security
--- End Message ---
--- Begin Message ---Hi gang: The manual says: http://www.php.net/nl2br That I could use the function like so (Example #2): $new = nl2br($string, false); But when I do, I get: Warning: Wrong parameter count for nl2br() in /home... What's up with that? I am using PHP Version 5.2.10 Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---