Jump to content

[SOLVED] variable


qbox

Recommended Posts

Hi to all

In my school we learn some stuff for php and they teach us to write all code in one variable. Like this for example

 

$Html = "<html>";

$Html .= "<head>";

$Html .= "</head>";

$Html .= "<body>";

$Html .= "<a href .........>";

.......... ANOTHER HTML CODE FOR EXAMPLE.........

$Html .= "</body>";

$Html .= "</html>";

 

When I open the site every look fine but when I open a page source I see that all code is writen in one line. Like this

<html><head></head><body><a href .................>.......... ANOTHER HTML CODE FOR EXAMPLE.........</body></html>

 

Can someone give me some tips how to write PHP code and to not be in one line?

I think that you got the point.

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/114338-solved-variable/
Share on other sites

Try finishing each line with the return character (\n in *nix):

 

<?php
$Html = "<html>\n";
$Html .= "<head>\n";
$Html .= "</head>\n";
$Html .= "<body>\n";
$Html .= "<a href .........>";
.......... ANOTHER HTML CODE FOR EXAMPLE.........
$Html .= "</body>\n";
$Html .= "</html>";
?>

Link to comment
https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587955
Share on other sites

Or

<?php
$html = array();
$html[] = '<html>';
$html[] = '<head>';
$html[] = '</head>';
$html[] = '<body>';
$html[] = '<a href .........>';
$html[] = '......... ANOTHER HTML CODE FOR EXAMPLE.........';
$html[] = '</body>';
$html[] = '</html>';
echo implode("\n",$html)."\n";
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587959
Share on other sites

Or:

 

$options = array("indent" => true,

                        "indent-spaces" => 4,

                        "wrap" => 72,

                        "output-xhtml" => true);

$tidy = new tidy();

$tidy->parseString($Html, $options);

$tidy->cleanRepair();

echo $tidy;

Link to comment
https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587962
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.