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 <br> or <p>. In case of double or more breaks we’ll get a paragraph but in case of one break we’ll have <br>.

$text = 'Lorem ipsum\r\n\r\ndolor sit\r\namet.';
// double or more nl to <p>
$text = preg_replace('/(\r?\n){2,}/', '</p><p>', $text);
// nl to <br>
$text = preg_replace('/(\r?\n)+/', '<br />', $text);
echo '<p>' . $text . '</p>';

output: <p>Lorem ipsum</p><p>dolor sit<br />amet.</p>

One side shadow in CSS3

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;
}