Jump to content

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


ajsuk

Recommended Posts

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:
[code]<?php
$text = '<? echo $status[2] ?>';
include("/blahblah/myinclude.php")
?>[/code]

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

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)
Link to comment
Share on other sites

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

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.
Link to comment
Share on other sites

Why are you putting tags around this?

[code=php:0]
<? echo $status[2] ?>
[/code]

You are already in PHP mode with this code block:

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

Try this:

[code=php:0]
<?php
$text = $status[2];
include("/blahblah/myinclude.php")
?>
[/code]
Link to comment
Share on other sites

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.


Link to comment
Share on other sites

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 [u]only[/u] 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.  :(
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.