Forum Moderators: coopster

Message Too Old, No Replies

Using echo statement within include

Using echo statement within include

         

Sofia_A

2:16 pm on Dec 18, 2010 (gmt 0)

10+ Year Member



I know this is basic, which is why it's irritating me that I can't work it out.

My statements are thus:


<?php include ("authorspage.php"); ?>

<?php echo "$thisAuthor"?>

I want to do this:

<?php include ("<?php echo "$thisAuthor"?>.php"); ?>

or so you can see more clearly: <?php include ("$thisAuthor.php"); ?>


But obviously I can't put the echo like that within this statement.

Help? :)

Frank_Rizzo

4:37 pm on Dec 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't understand what you are trying to do here. Do you just want to include whatever the $thisAuthor variable is?

What you have already will work:

<?php include("$thisAuthor.php"); ?>

If $thisAuthor = "shakespeare" then you will include the file shakespeare.php

Why do you need the echo?

Sofia_A

6:44 pm on Dec 18, 2010 (gmt 0)

10+ Year Member



Okay well my code is actually this:

<?php include ("$pageRef.html"); ?>

Which I thought would work, but it doesn't, so I thought there must be more to it?

And yes, that's what I want it to do, just as you mention.

Sofia_A

6:45 pm on Dec 18, 2010 (gmt 0)

10+ Year Member



Oh, wait, my bad... just a silly coding mistake.... ha ha. It does work, just as I want it to. As you were, thanks :)