canadabeeau Posted January 22, 2010 Share Posted January 22, 2010 Hi guys and gals, I have a PHP script echoing my css out of a mysqlDB. Now when it echos out all the content of the field it places them (a) on all the same line or (b) with no indentation [(b) applies to (a)] For example html,body{ background-color: #ffffff; padding: 0 0 0 0; margin: 0 0 0 0; /*background-image:url(/images/fullbg.jpg);*/ /*background-repeat:repeat-x;*/ font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #686868; } wether I want html,body{ background-color: #ffffff; padding: 0 0 0 0; margin: 0 0 0 0; /*background-image:url(/images/fullbg.jpg);*/ /*background-repeat:repeat-x;*/ font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #686868; } Any ideas how I can add the " " before it echos? it echos the "html,body{" and "}" separate so there should be a way to make the rest indent " " when it echos? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/189397-spacing/ Share on other sites More sharing options...
btherl Posted January 22, 2010 Share Posted January 22, 2010 That's a tricky one, as you need to parse the css to know where to put the indents. Is it possible to include indents in the database itself? If you only have a single level of indentation you could have a while loop that goes through each line, and remembers if it's currently inside an item or outside. If it's inside then it indents, if it's outside (or at the "}" end marker) then it doesn't indent. Link to comment https://forums.phpfreaks.com/topic/189397-spacing/#findComment-999759 Share on other sites More sharing options...
oni-kun Posted January 22, 2010 Share Posted January 22, 2010 That's a tricky one, as you need to parse the css to know where to put the indents. Is it possible to include indents in the database itself? If you only have a single level of indentation you could have a while loop that goes through each line, and remembers if it's currently inside an item or outside. If it's inside then it indents, if it's outside (or at the "}" end marker) then it doesn't indent. Why not iterate it through a loop? +1 and -1 ignore those lines, echo \t to..er..tabulate it. Link to comment https://forums.phpfreaks.com/topic/189397-spacing/#findComment-999772 Share on other sites More sharing options...
canadabeeau Posted January 23, 2010 Author Share Posted January 23, 2010 so what should I do, I don't exactly get oni-kun's suggestion?! Link to comment https://forums.phpfreaks.com/topic/189397-spacing/#findComment-1000408 Share on other sites More sharing options...
canadabeeau Posted February 2, 2010 Author Share Posted February 2, 2010 any ideas I tried using $value = ' '.$row['value']; and echoing it but again it only does it for the first entry :-( any ideas ie is does background.... font-style: ..... Link to comment https://forums.phpfreaks.com/topic/189397-spacing/#findComment-1005377 Share on other sites More sharing options...
btherl Posted February 3, 2010 Share Posted February 3, 2010 A good start would be converting it into an array. $lines = preg_split("/[\n\r]+/", $row['value']); Then you can loop over the lines, deciding if you want to indent or not for each one. At the end join them together using $final_value = implode("\n", $lines); Link to comment https://forums.phpfreaks.com/topic/189397-spacing/#findComment-1005857 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.