Jump to content


Photo

Including contents of strings?


  • Please log in to reply
8 replies to this topic

#1 Adastra

Adastra
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 01 August 2006 - 09:32 AM

I have a document structured like this:
<?
if ($_GET['p'] == "name1") {
my contents 
} elseif ($_GET['p'] == "name2") {
my contents 
} elseif ($_GET['p'] == "name3") {
my contents 
}
?>
and so on.

But now I need a string which gives me the contents of two of those strings, which somewhat includes the content of two of the strings in a new one together.
elseif ($_GET['p'] == "name_all") {
content of name2 and name3
}

How can I do that? include() doesn't work, and I've tried various other stuff with echo, $_GET and print, but nothing works! I'm sure you can easily do this with some function I don't know about.

Thanks in advance :)

#2 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 01 August 2006 - 09:40 AM

Can you be more specific I dont understand what you mean to say
I am a PHP Guru, ask me questions if you want to

#3 Adastra

Adastra
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 01 August 2006 - 09:42 AM

I want something like this:
elseif ($_GET['p'] == "name_all") {
content of ($_GET['p'] == "name2") and ($_GET['p'] == "name3")
}

I don't know how to explain it better.

#4 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 01 August 2006 - 10:13 AM

Nope, still not clear. Do you mean you want to test to see if $_GET["p"] contains "name2" and "name3"?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#5 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 01 August 2006 - 10:25 AM

This would work perfectly
I get wat you mean
elseif ($_GET['p'] == "name_all")
{
include("$_SERVER[SCRIPT_FILENAME]?p=name2");
include("$_SERVER[SCRIPT_FILENAME]?p=name3");
}

See its simple if you use get to get the content you can include the same script with different get parameters.
:)
hope dat helps
I am a PHP Guru, ask me questions if you want to

#6 Adastra

Adastra
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 01 August 2006 - 12:16 PM

Hmmpf, it's not working, I get this error (multiple times):
Warning: main(): Failed opening '/var/www/index.php?p=page3' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/unisys-outsourcing/index.php on line 5

#7 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 01 August 2006 - 12:18 PM

How about
include(__FILE__."?p=name2");

I'm just a guy who likes to code for fun...

#8 Adastra

Adastra
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 01 August 2006 - 12:45 PM

Nope, same error there :/

#9 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 01 August 2006 - 12:48 PM

then dun use vars like $_SERVER[SCRIPT_FILENAME] use the name like in this case index.php?p=name2 [/3]
I am a PHP Guru, ask me questions if you want to




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users