ajsuk Posted August 4, 2006 Share Posted August 4, 2006 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]<?phpecho "$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 More sharing options...
ronverdonk Posted August 4, 2006 Share Posted August 4, 2006 Depends on what you do in your include file before you echo the variable.Ronald 8) Link to comment https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69348 Share on other sites More sharing options...
ajsuk Posted August 4, 2006 Author Share Posted August 4, 2006 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 https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69353 Share on other sites More sharing options...
HeyRay2 Posted August 4, 2006 Share Posted August 4, 2006 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 https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69358 Share on other sites More sharing options...
ajsuk Posted August 4, 2006 Author Share Posted August 4, 2006 because it has to act as PHP when its transfered in to the include page. Link to comment https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69460 Share on other sites More sharing options...
kenrbnsn Posted August 4, 2006 Share Posted August 4, 2006 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 Link to comment https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69464 Share on other sites More sharing options...
ronverdonk Posted August 4, 2006 Share Posted August 4, 2006 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 https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69465 Share on other sites More sharing options...
redarrow Posted August 4, 2006 Share Posted August 4, 2006 if the code works good luck.dam beat to it,[code]<?php$stat=array("what_ever","what_ever","my name is redarrow");foreach($stat AS $status ){$text = $status[2];include("/blahblah/myinclude.php");}?>[/code] Link to comment https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69470 Share on other sites More sharing options...
ajsuk Posted August 4, 2006 Author Share Posted August 4, 2006 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 https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69473 Share on other sites More sharing options...
HeyRay2 Posted August 4, 2006 Share Posted August 4, 2006 But your include file is already in PHP mode:[b]/blahblah/myinclude.php[/b][code]<?phpecho "$text"; // Text Inc?>[/code]Which translates to bring read as:[code]echo '<? echo $status[2] ?>';[/code] Link to comment https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69475 Share on other sites More sharing options...
HeyRay2 Posted August 4, 2006 Share Posted August 4, 2006 Did you try this?[code=php:0]<?php$text = $status[2];include("/blahblah/myinclude.php")?>[/code]If not, try it out and let us know if it works. Link to comment https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69477 Share on other sites More sharing options...
ajsuk Posted August 4, 2006 Author Share Posted August 4, 2006 ah, yes, I've got it!! *smacks head on table* Must be one of those days, thanks alot all! Link to comment https://forums.phpfreaks.com/topic/16574-solvedhow-to-echo-php-in-to-an-include/#findComment-69481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.