tag
- if(strpos($string, '') === false)
- {
- return str_replace("\n","", $string);
- }
-
- // If there is a , we have to split by line
- // and manually replace the linebreaks
-
- $strArr=explode("\n", $string);
-
- $output="";
- $preFound=false;
-
- // Loop over each line
- foreach($strArr as $line)
- { // See if the line has a . If it does, set $preFound to true
- if(strpos($line, "") !== false)
- {
- $preFound=true;
- }
- elseif(strpos($line, "
") !== false)
- {
- $preFound=false;
- }
-
- // If we are in a pre tag, add line and also add \n, else add the line without \n
- if($preFound)
- {
- $output .= $line . "\n";
- }
- else
- {
- $output .= $line ;
- }
- }
-
- return $output;
+ $savestart = str_replace('$', '\x01', $startbb);
+ $replace = false;
+
+ $xpath = new DomXPath($doc);
+
+ $list = $xpath->query("//".$oldnode);
+ foreach ($list as $oldNode) {
+
+ $attr = array();
+ if ($oldNode->attributes->length)
+ foreach ($oldNode->attributes as $attribute)
+ $attr[$attribute->name] = $attribute->value;
+
+ $replace = true;
+
+ $startbb = $savestart;
+
+ $i = 0;
+
+ foreach ($attributes as $attribute => $value) {
+
+ $startbb = str_replace('\x01'.++$i, '$1', $startbb);
+
+ if (strpos('*'.$startbb, '$1') > 0) {
+
+ if ($replace and (@$attr[$attribute] != '')) {
+
+ $startbb = preg_replace($value, $startbb, $attr[$attribute], -1, $count);
+
+ // If nothing could be changed
+ if ($count == 0)
+ $replace = false;
+ } else
+ $replace = false;
+ } else {
+ if (@$attr[$attribute] != $value)
+ $replace = false;
+ }
+ }
+
+ if ($replace) {
+ $StartCode = $oldNode->ownerDocument->createTextNode($startbb);
+ $EndCode = $oldNode->ownerDocument->createTextNode($endbb);
+
+ $oldNode->parentNode->insertBefore($StartCode, $oldNode);
+
+ if ($oldNode->hasChildNodes()) {
+ foreach ($oldNode->childNodes as $child) {
+ $newNode = $child->cloneNode(true);
+ $oldNode->parentNode->insertBefore($newNode, $oldNode);
+ }
+ }
+
+ $oldNode->parentNode->insertBefore($EndCode, $oldNode);
+ $oldNode->parentNode->removeChild($oldNode);
+ }
+ }
+ return($replace);
}
+function _replace_code_cb($m){
+ return "".str_replace("\n","
\n",$m[1]). "
";
+}
+
+function html2bbcode($message)
+{
+
+ $message = str_replace("\r", "", $message);
+
+ $message = preg_replace_callback("|([^<]*)
|ism", "_replace_code_cb", $message);
+
+ $message = str_replace(array(
+ "