Page 1 of 1

php output

Posted: Tue Sep 20, 2011 6:53 am
by YoussefSiblini
Hi I am trying to output a message to the user:

Code: Select all

       
                $msgToUser = 
		"
		    <div style=\"float:left\">
			  <br /><br /><h3><font color=\"#00a651\"><strong>Your account has been activated. <br /><br />
              You are ready to log in and began your swap process.</strong></font></h3>
			  If you need more help about the swap process, take a look at <a href=\"http://www.areeban.com/howitwork.php\">how it work</a> page.
			</div>
			<div>
			  hello
			   <?php include_once \"includes/side/search.php\";?>
			</div>
		";
I want to include the search.php as you can see from the code above, I used this <?php include_once \"includes/side/search.php\";?> to include it but it is out putting it blank.

Youssef

Re: php output

Posted: Tue Sep 20, 2011 9:03 am
by Eric!
try

Code: Select all

<?php include_once "includes/side/search.php"; ?>
without the \" and double check the path is correct from the directory where this include file is being loaded.

Re: php output

Posted: Tue Sep 20, 2011 9:18 am
by YoussefSiblini
I took them off, now I am getting this error:

Code: Select all

Parse error: syntax error, unexpected T_STRING in /home/areebanc/public_html/register/activation.php on line 49
line 49 is <?php include_once "includes/side/search.php";?>

The code:

Code: Select all

<?php         
                $msgToUser = 
		"
		    <div style=\"float:left\">
			  <br /><br /><h3><font color=\"#00a651\"><strong>Your account has been activated. <br /><br />
              You are ready to log in and began your swap process.</strong></font></h3>
			  If you need more help about the swap process, take a look at <a href=\"http://www.areeban.com/howitwork.php\">how it work</a> page.
			</div>
			<div>
			   <?php include_once "includes/side/search.php";?>
			</div>
		";
?>
And I am outputting the $msgToUser:

Code: Select all

<?php echo $msgToUser ?>

Re: php output

Posted: Tue Sep 20, 2011 9:56 am
by Eric!
Sorry I didn't notice you were putting this php code inside a variable. Change it back. You do need to escape the " marks with \".

So what happens when you run the includes/side/search.php by itself? Is the problem with your search.php script?

Re: php output

Posted: Tue Sep 20, 2011 10:07 am
by YoussefSiblini
if I run includes/side/search.php any where outside this php code it work fine,
I am using the full path now which is http://areeban.com/includes/side/search.php if you take a look it work fine.

Re: php output

Posted: Tue Sep 20, 2011 10:36 am
by AbraCadaver
There are better ways, such as using a template for the html, but the way you are doing it, you need to do something like this:

Code: Select all

<?php
ob_start();
include_once "includes/side/search.php";
$search = ob_get_clean();

$msgToUser =
                "
                    <div style=\"float:left\">
                          <br /><br /><h3><font color=\"#00a651\"><strong>Your account has been activated. <br /><br />
              You are ready to log in and began your swap process.</strong></font></h3>
                          If you need more help about the swap process, take a look at <a href=\"http://www.areeban.com/howitwork.php\">how it work</a> page.
                        </div>
                        <div>
                          $search
                        </div>
                ";
?>

Re: php output

Posted: Tue Sep 20, 2011 10:43 am
by YoussefSiblini
Thank you this worked perfect, but I am not leaving you tell you tell me how this work. lool

Re: php output

Posted: Tue Sep 20, 2011 12:24 pm
by AbraCadaver
Well, I am assuming that the included file is echoing data. ob_start() starts an output buffer that buffers the output of the include. You then assign that output to a variable and end and clear the buffer. So nothing is outputted but it is assigned to the variable that you can use later.

Re: php output

Posted: Tue Sep 20, 2011 12:51 pm
by YoussefSiblini
Thank you :)