RE: Quick Question: Line Breaks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09 January 2004 03:58, Jacob Hackamack wrote:

> Hello,
> 
> I have a couple of quick questions.  When I execute this code on my
> php page (I know that the .PSD image isn¹t web ready, but Safari does
> what I need it to do :) ) it displays the entire source as one line. 
> Is there anyway to have it be broken.  I have read places (internet
> sites) that say that the following solutions might work:
>     echo OE¹;\n\n
>     echo OE¹\n\n ;
>     echo OE\n\n¹;
> 
> None of them seem to work, am I doing something wrong?
> 
> 
> echo '<meta http-equiv="content-type" content="text/html;
> charset=utf-8">'; echo '<html>';
> echo '<head>';
> echo '<title>';
> echo 'FilmCanister Desktops';
> echo '</title>';
> echo '</head>';
> echo '<body>';
> echo '<center>';
> echo '<img src="images/Rotating.psd">';
> echo '<h2>';
> echo 'Coming Soon....Desktop Pictures (2.83 GB Worth)</h2>'; echo
> '</center>'; echo '</body>';
> echo '</html>';

The reason you have it all on one line is because you haven't echoed any
newlines.  You have a number of options to do this.  As there is no variable
interpolation anywhere in there, you could just break out of PHP and do it
as straight HTML:

...
?>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<html>
<head>
<title>
FilmCanister Desktops
</title>
</head>
<body>
<center>
<img src="images/Rotating.psd">
<h2>
Coming Soon....Desktop Pictures (2.83 GB Worth)</h2>
</center>
</body>
</html>
<?php
...

Or you could echo the whole thing in one go (since you can have newlines in
a PHP string):

echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">
<html>
<head>
...
</body>
</html>
';

If you plan to have variables in there at some point, you can either use
<?php echo $var ?> segments, or use a heredoc:

echo <<<END
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<html>
<head>
<body>
<center>
<img src="images/$name.psd">
...
</body>
</html>
END;

or, again, you could use a multi-line string -- but this time double-quoted
to give interpolation (but note that you now have to escape all your
embedded double quotes):

echo "
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
<html>
<head>
<body>
<center>
<img src=\"images/$name.psd\">
...
</body>
</html>
";

Which route you choose is pretty much personal taste -- personally, if I
have a page that's mostly straight HTML with not much PHP code, I write it
as HTML with embedded PHP snippets, but I know some people think that looks
weird or ugly...!

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux