Jump to content


Photo

[Solved]How to echo PHP in to an include?


  • Please log in to reply
11 replies to this topic

#1 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 04 August 2006 - 06:06 PM

So I'd like to be able to echo php in to an include, but php really doesn't seem to like me trying to include php in an echo.

Heres an example of what I've tried, hopefully you can grasp the idea of what I'm trying to do. :)

Trying to echo in bit of PHP:
<?php
$text = '<? echo $status[2] ?>';
include("/blahblah/myinclude.php")
?>

Then output in to the included file:
<?php
echo "$text"; // Text Inc
?>

It doesn't like being formated like that, could somebody tell me what I'm doing wrong and how to fix it?

Thanks in advance!  8)

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 06:08 PM

Depends on what you do in your include file before you echo the variable.

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#3 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 04 August 2006 - 06:17 PM

I think it's this bit thats screwing it up:
$text = '<? echo $status[2] ?>';

It'll include whats in there no probs until I put the php tags around it... And putting them in at the other end (in the included file) doesn't work either.

#4 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 04 August 2006 - 06:27 PM

Why are you putting tags around this?

<? echo $status[2] ?>

You are already in PHP mode with this code block:

<?php
$text = '<? echo $status[2] ?>';
include("/blahblah/myinclude.php")
?>

Try this:

<?php
$text = $status[2];
include("/blahblah/myinclude.php")
?>


#5 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 04 August 2006 - 09:50 PM

because it has to act as PHP when its transfered in to the include page.

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 August 2006 - 10:03 PM

When you include a file into a script, it is treated as inline code by the PHP processor. It is no different than if you typed in yourself.

How do you think included files work?

Ken

#7 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 10:04 PM

Ajsuk ... we may have a problem here. As you have coded yourself before the $text=... statement, you are already in PHP when you do the assignment to $text.

Whatever you assign, in this PHP part, to $text is in variable $text. When you assign 'Balblablax' to it, it will still contain 'Balblablax' when you echo it in your myinclude.php file.



RTFM is an almost extinct art form, it should be subsidized.

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 August 2006 - 10:10 PM

if the code works good luck.

dam beat to it,

<?php

$stat=array("what_ever","what_ever","my name is redarrow");

foreach($stat AS $status ){

$text = $status[2];

include("/blahblah/myinclude.php");

}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 04 August 2006 - 10:15 PM

Yeah  :-\

So is there any way to change the "Balblablax" to "<? echo $status[2] ?>" without it getting annoyed?

the "<? echo $status[2] ?>" bit is supposed to trigger another script earlier in the include file to produce a server status (from server #3) and I only want it to display that 3rd server result in this case. So this is why I'm trying to tell it to echo that status in this example.

If theres any other way to do it, I'm all ears. Sorry for the confusion, I'm not up on all this.  :(

#10 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 04 August 2006 - 10:17 PM

But your include file is already in PHP mode:

/blahblah/myinclude.php
<?php
echo "$text"; // Text Inc
?>

Which translates to bring read as:
echo '<? echo $status[2] ?>';


#11 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 04 August 2006 - 10:18 PM

Did you try this?

<?php
$text = $status[2];
include("/blahblah/myinclude.php")
?>

If not, try it out and let us know if it works.

#12 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 04 August 2006 - 10:21 PM

ah, yes, I've got it!! *smacks head on table* Must be one of those days, thanks alot all!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users