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