0

I'm creating a php page and I'm using include statements to load the contents but it's having a bad effect on the output. Here are my files:

index.php:

<div class="sectionSpacer"></div>
<?php include("newsection.php"); ?>
<div class="sectionSpacer"></div>

newsection.php:

<div class="sectionInner">
    <div id="details">
        <?php echo $details; ?>
    </div>
</div>

$details:

My email address is <?php echo $my_email; ?>

The problem is that while the div is being displayed, $details isn't echoing out the email address on the index page. How can this be resolved?

4
  • 1
    Where is $details assigned a value? Commented Apr 5, 2015 at 12:40
  • Where is $my_email defined? Commented Apr 5, 2015 at 14:23
  • @Drakes It is defined at the top of my index.php page Commented Apr 5, 2015 at 14:25
  • As long as it is defined, my answer should display your email address Commented Apr 5, 2015 at 14:57

3 Answers 3

2

Modify ur newsection.PHP to following:

<?php

$txt= <<< EOPAGE
<div class="sectionInner">
<div id="details">
    $details
</div>
</div>
 EOPAGE;

echo $txt;
?>

The declaration of variables details and my_mail:

   $my_email= "some.email@example. com;
   $details="My email address is". $my_email;

I am sure this will work

Sign up to request clarification or add additional context in comments.

Comments

1

In the case you are trying to echo the string $details of mixed HTML/PHP (like from a database), you can echo it this way:

echo eval(' ?>'.$details.'<?php ');

Then change your code to this:

<div class="sectionInner">
    <div id="details">
        <?php echo eval(' ?>'.$details.'<?php '); ?>
    </div>
</div>

Of course if you can rework your setup to avoid eval'ing PHP code, please, please do that.

1 Comment

How did this work out for you? Were you able to try it with your code and verify that it works for you?
0

What you are trying to do cannot be done, and you should know this if you understand how code is executed. put -myemail- into

$variable = "my email is -myemail-";
$variable = str_replace($variable,"-myemail-",$myemail);
echo $variable;

8 Comments

Ok, What about if the echoed $details contains a <?php ?> statement. That's what isn't showing up - how can this be corrected?
try escaping it, that is a weird case.
Take a look at my updated question! How do I escape?
I'm sorry but can you show how that would work on my original post code?
I'm sorry but that doesn't really make sense to me. $details IS being echoed but the email isn't, as stated in my question.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.