0

I have the following code in php and I am failing to output what is contained in the 'include_once('aux_files/requestAuthParticip_aux.php')' line. I suspect I have not got the syntax correct but do not know how to fix this. please can someone advise?

 <?php
 $requestMemBox = '
<div id="topAuth">
    <div id="authorHeading" data-pubid='.$pubID.'>Authors Taking Questions</div>
    <div id="inviteAuthor">
        <input id="searchAutorInvite" type="text" placeholder="Invite Author"> 
        <div id="wrapSuggestAuthor"></div>
    </div>  
</div>  
<div id="wraplistOfAuthors">
    <?php include_once('aux_files/requestAuthParticip_aux.php'); ?>
</div>
 ';

 ?>
4
  • you're already in PHP <?php include_once('aux_files/requestAuthParticip_aux.php'); ?> and this php.net/manual/en/function.error-reporting.php would have thrown you something about it. Commented Dec 15, 2015 at 20:36
  • i've removed the <?php ?> but its still not giving me what I need compared to what i would get if I had written it straight in html Commented Dec 15, 2015 at 20:40
  • Your code is in the '$requestMemBox'. so maybe you would try to put this in double quotes: <?php include_once("aux_files/requestAuthParticip_aux.php"); ?> Commented Dec 15, 2015 at 20:43
  • You could do "aux_files/requestAuthParticip_aux.php" instead of 'aux_files/requestAuthParticip_aux.php' or \'aux_files/requestAuthParticip_aux.php\' since you use simple quotes for setting the variable content. Commented Dec 15, 2015 at 20:45

3 Answers 3

1

You can use ob_get_contents();

<?php
  ob_start();
  include('aux_files/requestAuthParticip_aux.php');
  $output .= ob_get_contents();
  ob_end_clean();
?>
<?php
 $requestMemBox = '
<div id="topAuth">
    <div id="authorHeading" data-pubid='.$pubID.'>Authors Taking Questions</div>
    <div id="inviteAuthor">
        <input id="searchAutorInvite" type="text" placeholder="Invite Author"> 
        <div id="wrapSuggestAuthor"></div>
    </div>  
</div>  
<div id="wraplistOfAuthors">
    '. $output  .'
</div>';
?>
Sign up to request clarification or add additional context in comments.

Comments

0

You're trying to assign an include to a variable, which isn't going to work, but you're also doing it in the middle of a string, which is definitely not going to work.

To achieve what you want, you should exit PHP mode, pull in the file's contents to append to your string, then re-enter PHP mode to continue processing as much as you want.

If the thing you're importing contains text you want inside your variable (which is how you're trying to use it right now), then something like this is probably what you want:

<?php
    $requestMemBox = '
<div id="topAuth">
    <div id="authorHeading" data-pubid='.$pubID.'>Authors Taking Questions</div>
    <div id="inviteAuthor">
        <input id="searchAutorInvite" type="text" placeholder="Invite Author"> 
        <div id="wrapSuggestAuthor"></div>
    </div>  
</div>  
<div id="wraplistOfAuthors">';

    $requestMemBox .= file_get_contents('aux_files/requestAuthParticip_aux.php');

    $requestMemBox .= '</div>';
 ?>

If your included script includes some actual functionality, then you really ought to include it up front and grab its value using a function call, and append that to your string.

Comments

0

replace this line

<?php include_once('aux_files/requestAuthParticip_aux.php'); ?>

with

';
ob_start();
include_once('aux_files/requestAuthParticip_aux.php'); 
$requestMemBox .= ob_get_clean();
$requestMemBox .= '</div>';

Is one way!

look up ob_start(); to see whats going on here.

Comments

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.