php output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

php output

Post 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
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: php output

Post 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.
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Re: php output

Post 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 ?>
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: php output

Post 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?
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Re: php output

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php output

Post 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>
                ";
?>
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Re: php output

Post by YoussefSiblini »

Thank you this worked perfect, but I am not leaving you tell you tell me how this work. lool
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php output

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Re: php output

Post by YoussefSiblini »

Thank you :)
Post Reply