Jump to content

spacing


canadabeeau

Recommended Posts

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

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

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

  • 2 weeks later...

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

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.