Forum Moderators: coopster

Message Too Old, No Replies

file.php,one,two,three commas in PHP includes?

Don't use the word G_E_T, removed when searching earlier...

         

JAB Creations

2:09 am on Dec 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First please don't use the word G_E_T so others who do searches with the remove switch may find this thread not knowing the terminology I'm inquiring about.

What is this called?

file.php,something

I only want to use one instance of that though I'm not finding the correct references?

- John

eelixduppy

6:55 pm on Dec 26, 2007 (gmt 0)



I'm going to use the "function" echo for this explanation. echo is a language construct and is not exactly a function in the same sense that make functions functions. Because it is a language construct, the syntax is more lax than a function, and the parenthesis can be excluded. So the following two statements are equivalent:

echo("example");


echo "example";

Now since echo [php.net]() can take more than one argument, you can echo multiple strings out at once:


echo("one","two","three","four","five");

But since this is a construct, we can also write this like this:


echo "one", "two", "three" ,"four" ,"five";

removing the parenthesis as they are not needed. As for include, you can only include one file at a time, however it is still a language construct therefore the parenthesis are still not required.


include "file.php";

I believe that there are a few language constructs that require the parenthesis but I don't know off the top of my head. Anyway, I hope that answers your question.

JAB Creations

7:05 pm on Dec 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, I had something in mind along what a friend tried. It took me some time to decipher, he essentially used explode. So while there is a way to do what he did it's neither referred to in a common way nor common from what I've thus far seen.

- John

eelixduppy

7:09 pm on Dec 27, 2007 (gmt 0)



I haven't seen multiple includes written with comma separators like that. It should come up with a syntax error...

henry0

10:42 pm on Dec 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps two years ago we had a thread with somehow a similar topic
coopster came with a nice "how to" to show us how he was including "many includes" that are frequently called for
Too bad I cannot find it, but possibly coopster will :)

JAB Creations

12:34 am on Dec 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The issue was a vague beginning to what I'm now dealing with at this thread in the JavaScript forum...
[webmasterworld.com...]

Here is the explode script my friend uses, hopefully it will help someone out. Again I'm dealing with the AJAX HTTP query issue (HTTP query (?query_property=query_value)) not being passed to PHP and it's the AJAX script I've been using. Anyway you guys probably want explosions so here you go (and don't ask me how it works!) ;)

- John

//If other scripts are requested, load them toooooooo
if (!empty($_GET)){
$i=null;
foreach($_GET as $key=>$val){
if(!empty($i)){
$i .= ',';
}
$i .= $key;
}
if($i === 'all') {
$i = 'dhtml,sounds,chat,fscroll,pkeys,target,prompt';
}
$opts = explode(',',$i);
doStart();
foreach($opts as $name){
loadScript($name);
}
loadScript('focus');
// doClose();
}

System

1:19 am on Dec 28, 2007 (gmt 0)

redhat



The following 2 messages were cut out to new thread by eelixduppy. New thread at: php/3536259.htm [webmasterworld.com]
2:28 am on Dec. 28, 2007 (est -5)

coopster

10:38 pm on Dec 28, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



henry0, I believe you are likely referring to the PHP Forum Library thread Good PHP solutions to small problems [webmasterworld.com] where I described one way to control your included files on a shared hosting platform. It doesn't quite fit the issue here though ...

JAB_Creations, what is happening here is certain values are being selected or requested via GET in the browser and here in your server-side script the programmer is collecting those values, accumulating them in a comma-separated list. Once the collection is completed, the list is exploded [php.net] into an array for further processing via a foreach loop which runs a "loadScript" function. The "loadScript" presumably includes [php.net] a specified file based on the selections passed.

You can only include one file via the include statement, but you can certainly loop through an array of specified files including them one-by-one consecutively.