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
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
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
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
Share on other sites

What operating system do you use?  If you use Ubuntu, you have to do:

 

sudo apt-get install php5-tidy

 

>_>  If you use Windows it should be installed....Save this as info.php:

<?php

phpinfo();

?>

 

And do a Ctrl+F for "tidy" when you open the page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.