Archive for November, 2011

New line to paragraph in PHP

Here’s an example of how to convert new line (LF – line feed, ‘\n’) or carriage return (CR, ‘\r’) followed by new line (CR+LF, ‘\r\n’) to
or

. In case of double or more breaks we’ll get a paragraph but in case of one break we’ll have
.

$text = 'Lorem ipsum\r\n\r\ndolor sit\r\namet.';
// double or more nl to 

$text = preg_replace('/(\r?\n){2,}/', '

'

, $text); // nl to
$text = preg_replace('/(\r?\n)+/', '
'
, $text); echo '

'

. $text . '';

output:

Lorem ipsum

dolor sit
amet.

One side shadow in CSS

As You may suppose, there isn’t a standard way to set the box shadow for only one side of the box or leave one side of the element without a shadow. But You can reach it by using simple CSS tricks. Here You can analyze two examples.

In the first example, we will set box-shadow for only one side of the box.

In the second sample, only one side of the element will be without a shadow.

I hope everybody will understand this CSS so I won’t provide any other description. More code, less water)

Let’s start:

One side shadow

  <div></div>
  div {
    margin: 30px;
    height: 100px;
    width: 100px;
    position: relative;
    overflow: hidden;
    padding: 0 7px 0 0;
  }
 
  div:before {
    position: absolute; 
    content: ' '; 
    top: 0px; 
    right: 7px; 
    bottom: 0;
    left: 0; 
    background-color: transparent; 
    box-shadow: 0 0 5px black;
    border: 1px solid red;
  }

One side without shadow

  <div></div>
  div {
    margin: 30px;
    height: 100px;
    width: 100px;
    position:relative;
    overflow: hidden;
    padding: 7px 7px 0 7px;
  }
 
  div:before {
    position: absolute; 
    content: ' '; 
    top: 7px; 
    right: 7px; 
    bottom: -7px;
    left: 7px; 
    background-color: transparent; 
    box-shadow: 0 0 5px black;
    border: 1px solid red;
  }