Pues eso tengo una funcion que reemplaza etiquetas HTML a BBC con preg_replace de PHP, el problema que tengo es que funciona perfectamente siempre y cuando es un sólo registro, pero si la utilizo mediante un ciclo while no reemplaza nada..
Esta es la funcion que reemplaza:
Código PHP:
Ver originalfunction fixBBCTags($body)
{
//code without value pattern
$body = preg_replace('#<pre\s\ class=(\'|")_prettyXprint\1>(.*?)<\/pre>#is','[code]$2[/code]',$body); //normal code
$body = preg_replace('#<pre\s+class=(\'|")_prettyXprint\s+_lang-auto\s+_linenums:(?:.*?)\1>(.*?)<\/pre>#is','[code]$2[/code]',$body); //code with value pattern
$body = preg_replace('#<pre\s+class=(\'|")_prettyXprint\s_lang-(.*?)\s_linenums:(?:.*?)\1>(.*?)<\/pre>#is','[code=$2]$3[/code]',$body); //code with value pattern version 2
$body = preg_replace('#<pre\s+class=(\'|")_prettyXprint\s+_lang-(.*?)\1>(.*?)<\/pre>#is','[code=$2]$3[/code]',$body); //geshi block
$body = preg_replace('#<pre\s+class=(\'|")(.*?)\sgeshi_block\1>(.*?)<\/pre>#is','[code=$2]$3[/code]',$body); //images
$body = preg_replace('#<img\s+src=(\'|")(.*?)\1\salt=\1(?:.*?)\1>#is','[img]$2[/img]',$body); //list decimal
$body = preg_replace('#<ul\s+class=(\'|")bbc\s+bbcol\s+decimal\1>(.*?)<\/ul>#is','[list type=decimal]$2[/list]',$body); //normal quote
$body = preg_replace('#<blockquote\s+class=(\'|")ipsBlockquote\1>(.*?)<\/blockquote>#is','[quote]$2[/quote]',$body); //email
$body = preg_replace('#<a\s+data-ipb=(\'|")nomediaparse\1\s+href=\1mailto:(.*?)\1>(.*?)<\/a>#is','[email]$2[/email]',$body); //list normal
$body = preg_replace('#<ul\s+class=(\'|")bbc\1>(.*?)<\/ul>#is','[list]$2[/list]',$body); //Center
$body = preg_replace('#<p\s+style=(\'|")text-align:center;\1>(.*?)<\/p>#is','[center]$2[/center]',$body); //left
$body = preg_replace('#<p\s+style=(\'|")text-align:left;\1>(.*?)<\/p>#is','[left]$2[/left]',$body); //right
$body = preg_replace('#<p\s+style=(\'|")text-align:right;\1>(.*?)<\/p>#is','[right]$2[/right]',$body); //ftp
$body = preg_replace('#<a\s+data-ipb=(\'|")nomediaparse\1\s+href=\1ftp:(?:.*?)\1>(.*?)<\/a>#is','[ftp]$2[/ftp]',$body); //underline
$body = preg_replace('#<u>(.*?)<\/u>#is','[u]$1[/u]',$body); //strike
$body = preg_replace('#<strike>(.*?)<\/strike>#is','[s]$1[/s]',$body); //superindex
$body = preg_replace('#<sup>(.*?)<\/sup>#is','[sup]$1[/sup]',$body); //subindex
$body = preg_replace('#<sub>(.*?)<\/sub>#is','[sub]$1[/sub]',$body); //items list
$body = preg_replace('#<li>(.*?)<\/li>#is','[li]$1[/li]',$body); //quote with value pattern
$body = preg_replace('#<blockquote\s+class=(\'|")ipsBlockquote\1\s+data-author=\1(.*?)\1\s+data-cid=\1([0-9]+)\1\s+data-time=\1([0-9]+)\1>(.*?)<\/blockquote>#is','[quote author=$2 link=topic=.msg$3#msg$3 date=$4]$5[/quote]',$body); //italic
$body = preg_replace('#<em>(.*?)<\/em>#is','[i]$1[/i]',$body); //bold
$body = preg_replace('#<strong>(.*?)<\/strong>#is','[b]$1[/b]',$body); //color
$body = preg_replace('#<span\s+style=(\'|")color:(.*?);\1>(.*?)<\/span>#is','[color=$2]$3[/color]',$body); //font size
$body = preg_replace('#<span\s+style=(\'|")font-size:(.*?)px;\1>(.*?)<\/span>#is','[size=$2pt]$3[/size]',$body); //font type
$body = preg_replace('#<span\s+style=(\'|")font-family:(.*?),(?:.*?);\1>(.*?)<\/span>#is','[font=$2]$3[/font]',$body); //Url
$body = preg_replace('#<a\s+data-ipb=(\'|")nomediaparse\1\s+href=\1(.*?)\1>(.*?)<\/a>#is','[url=$2]$3[/url]',$body); //marquee
$body = preg_replace('#<marquee>(.*?)<\/marquee>#is','[move]$1[/move]',$body);
array('<br>','<br />','<p>','</p>',' '), array("\n", "\n",'','',' '), $body);
return $body;
}
Y aqui la utilizo, por ahí en la línea 32:
Código PHP:
Ver original "SELECT
p.pid AS id_msg, p.topic_id AS id_topic, p.post_date AS poster_time,
p.author_id AS id_member, SUBSTRING(t.title, 1, 255) AS subject,
SUBSTRING(p.author_name, 1, 255) AS poster_name,
SUBSTRING(p.ip_address, 1, 255) AS poster_ip,
p.use_emo AS smileys_enabled, IFNULL(p.edit_time, 0) AS modified_time,
SUBSTRING(p.edit_name, 1, 255) AS modified_name, t.forum_id AS id_board,
SUBSTRING(p.post, 1, 65534) AS body,
SUBSTRING(mem.email, 1, 255) AS poster_email, 'xx' AS icon
FROM " . $from_prefix ."posts AS p
LEFT JOIN " . $from_prefix ."topics AS t ON (t.tid = p.topic_id)
LEFT JOIN " . $from_prefix ."members AS mem ON (mem.member_id = p.author_id)
WHERE p.pid != 0
ORDER BY p.pid
LIMIT " . $i ."," . $limit);
{
$messages[$row['id_msg']] = array( 'id_msg' => $row['id_msg'],
'id_topic' => $row['id_topic'],
'poster_time' => $row['poster_time'],
'id_member' => $row['id_member'],
'subject' => $row['subject'],
'poster_name' => $row['poster_name'],
'poster_ip' => $row['poster_ip'],
'smileys_enabled' => $row['smileys_enabled'],
'modified_time' => $row['modified_time'],
'modified_name' => $row['modified_name'],
'id_board' => $row['id_board'],
'poster_email' => $row['poster_email'],
'icon' => $row['icon'],
);
}
Anteriormente lo intenté con varios parseadores HTML con el mismo resultado, ¿qué estaré haciendo mal?, ¿habrá otra manera de hacerlo?.
Saludos.