qbox Posted July 11, 2008 Share Posted July 11, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/ Share on other sites More sharing options...
Sulman Posted July 11, 2008 Share Posted July 11, 2008 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587955 Share on other sites More sharing options...
wildteen88 Posted July 11, 2008 Share Posted July 11, 2008 Or do $Html = "<html> <head> </head> <body> <a href .........> ......... ANOTHER HTML CODE FOR EXAMPLE......... </body> </html>"; echo $html Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587956 Share on other sites More sharing options...
kenrbnsn Posted July 11, 2008 Share Posted July 11, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587959 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 Or: $options = array("indent" => true, "indent-spaces" => 4, "wrap" => 72, "output-xhtml" => true); $tidy = new tidy(); $tidy->parseString($Html, $options); $tidy->cleanRepair(); echo $tidy; Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587962 Share on other sites More sharing options...
qbox Posted July 11, 2008 Author Share Posted July 11, 2008 WOW this was fast. Thank you all. how you suggest me to write the php code? What is the good choice? Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587967 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 Mine is the easiest and indents for you and fixes any improper tag structure you may have. Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587968 Share on other sites More sharing options...
qbox Posted July 11, 2008 Author Share Posted July 11, 2008 Thanks DarkWater. I mark this solved. Let me see how this work Thanks again to all. Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587971 Share on other sites More sharing options...
qbox Posted July 11, 2008 Author Share Posted July 11, 2008 DarkWater can you give me a little example how this work? I receive error on $tidy = new tidy(); Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587973 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 What version of PHP do you have? You may not have tidy installed, in which case my solution will not work. Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587977 Share on other sites More sharing options...
qbox Posted July 11, 2008 Author Share Posted July 11, 2008 PHP Version 5.2.5 any way to use kenrbnsn way without arrays? Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587982 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587983 Share on other sites More sharing options...
qbox Posted July 11, 2008 Author Share Posted July 11, 2008 cool I got it thanks to all. Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587985 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 Did Tidy work for you? Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587987 Share on other sites More sharing options...
qbox Posted July 11, 2008 Author Share Posted July 11, 2008 after installing yes I use some version of apachefriends XAMPP on ubuntu I make update and fork fine. Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-587994 Share on other sites More sharing options...
DarkWater Posted July 11, 2008 Share Posted July 11, 2008 Great. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/114338-solved-variable/#findComment-588001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.