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
https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/
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]
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.


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.  :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.