-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.blockquote.php
More file actions
35 lines (33 loc) · 865 Bytes
/
function.blockquote.php
File metadata and controls
35 lines (33 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
function toArray($str, $currLevel = 0, $i = 0) {
$return = array();
$lines = explode("\n", $str);
for($j = count($lines); $i < $j; $i++) {
$line = trim($lines[$i]);
$level = preg_replace('/^((?:>|\s)+).*/','\1', $line);
$level = substr_count($level, '>');
if($level == $currLevel) {
array_push($return, preg_replace('/^((?:>|\s)+)(.*)/','\2', $line));
}
else if($level > $currLevel) {
array_push($return, toArray(join("\n", $lines), $currLevel + 1, &$i));
} else if($level < $currLevel) {
$i--;
return $return;
}
}
return $return;
}
function toQuote($lines) {
$return = "<blockquote>\n";
foreach($lines as $line) {
if(is_array($line)) {
$return .= toQuote($line);
}
else {
$return .= $line . "\n";
}
}
$return .= "</blockquote>\n";
return $return;
}