[ create a new paste ] login | about

Link: http://codepad.org/aCmjv5HU    [ raw code | output | fork ]

PHP, pasted on Dec 4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$array = array(
  0 => '[This is a line of text',
  1 => 'and another',
  2 => 'and yet another.] [This is another line of text',
  3 => 'and another',
  4 => 'and another] [OK, so you get the idea.',
);


for($i = 0; $i < count($array); $i++) {
  $array[$i] = '<p>'.$array[$i].'</p>';
  $array[$i] = preg_replace('/\]/', '</p>', $array[$i]);
  $array[$i] = preg_replace('/\[/', '<p class="myclass">', $array[$i]);
  $array[$i] = preg_replace('/<p><p/', '<p', $array[$i]);
}

echo "<pre>";
var_dump($array);
?>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
<pre>array(5) {
  [0]=>
  string(45) "<p class="myclass">This is a line of text</p>"
  [1]=>
  string(18) "<p>and another</p>"
  [2]=>
  string(75) "<p>and yet another.</p> <p class="myclass">This is another line of text</p>"
  [3]=>
  string(18) "<p>and another</p>"
  [4]=>
  string(66) "<p>and another</p> <p class="myclass">OK, so you get the idea.</p>"
}


Create a new paste based on this one


Comments: