This code worked for me:
Not 100% accurate but it helps:
Thanks to https://gist.github.com/neo22s/2584465
, with minor modifications
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT post_id, post_text from phpbb_posts"; //adjust phpbb_
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$converted_post_text=tohtml($row['post_text']);
$post_id=$row['post_id'];
$updated_sql="UPDATE phpbb_posts SET post_text='".$converted_post_text."' WHERE post_id='".$post_id."'";
$conn->query($updated_sql);
echo $post_id . 'Done '. $converted_post_text;
echo '<br>';
sleep(1);
}
} else {
echo "0 results";
}
$conn->close();
function tohtml($text,$advanced=true,$charset='utf-8'){
//special chars
$text = htmlspecialchars($text, ENT_QUOTES,$charset);
/**
* This array contains the main static bbcode
* @var array $basic_bbcode
*/
$basic_bbcode = array(
'[b]', '[/b]',
'[i]', '[/i]',
'[u]', '[/u]',
'[s]','[/s]',
'[ul]','[/ul]',
'[li]', '[/li]',
'[ol]', '[/ol]',
'[center]', '[/center]',
'[left]', '[/left]',
'[right]', '[/right]',
);
/**
* This array contains the main static bbcode's html
* @var array $basic_html
*/
$basic_html = array(
'<b>', '</b>',
'<i>', '</i>',
'<u>', '</u>',
'<s>', '</s>',
'<ul>','</ul>',
'<li>','</li>',
'<ol>','</ol>',
'<div style="text-align: center;">', '</div>',
'<div style="text-align: left;">', '</div>',
'<div style="text-align: right;">', '</div>',
);
/**
*
* Parses basic bbcode, used str_replace since seems to be the fastest
*/
$text = str_replace($basic_bbcode, $basic_html, $text);
//advanced BBCODE
if ($advanced)
{
/**
* This array contains the advanced static bbcode
* @var array $advanced_bbcode
*/
$advanced_bbcode = array(
'#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.+)\[/color\]#Usi',
'#\[size=([0-9][0-9]?)](.+)\[/size\]#Usi',
'#\[quote](\r\n)?(.+?)\[/quote]#si',
'#\[quote=(.*?)](\r\n)?(.+?)\[/quote]#si',
'#\[url](.+)\[/url]#Usi',
'#\[url=(.+)](.+)\[/url\]#Usi',
'#\[email]([\w\.\-]+@[a-zA-Z0-9\-]+\.?[a-zA-Z0-9\-]*\.\w{1,4})\[/email]#Usi',
'#\[email=([\w\.\-]+@[a-zA-Z0-9\-]+\.?[a-zA-Z0-9\-]*\.\w{1,4})](.+)\[/email]#Usi',
'#\[img](.+)\[/img]#Usi',
'#\[img=(.+)](.+)\[/img]#Usi',
'#\[code](\r\n)?(.+?)(\r\n)?\[/code]#si',
'#\[youtube]http://[a-z]{0,3}.youtube.com/watch\?v=([0-9a-zA-Z]{1,11})\[/youtube]#Usi',
'#\[youtube]([0-9a-zA-Z]{1,11})\[/youtube]#Usi'
);
/**
* This array contains the advanced static bbcode's html
* @var array $advanced_html
*/
$advanced_html = array(
'<span style="color: $1">$2</span>',
'<span style="font-size: $1px">$2</span>',
"<div class=\"quote\"><span class=\"quoteby\">Disse:</span>\r\n$2</div>",
"<div class=\"quote\"><span class=\"quoteby\">Disse <b>$1</b>:</span>\r\n$3</div>",
'<a rel="nofollow" target="_blank" href="$1">$1</a>',
'<a rel="nofollow" target="_blank" href="$1">$2</a>',
'<a href="mailto: $1">$1</a>',
'<a href="mailto: $1">$2</a>',
'<img src="$1" alt="$1" />',
'<img src="$1" alt="$2" />',
'<div class="code">$2</div>',
'<object type="application/x-shockwave-flash" style="width: 450px; height: 366px;" data="http://www.youtube.com/v/$1"><param name="movie" value="http://www.youtube.com/v/$1" /><param name="wmode" value="transparent" /></object>',
'<object type="application/x-shockwave-flash" style="width: 450px; height: 366px;" data="http://www.youtube.com/v/$1"><param name="movie" value="http://www.youtube.com/v/$1" /><param name="wmode" value="transparent" /></object>'
);
$text = preg_replace($advanced_bbcode, $advanced_html,$text);
}
//before return convert line breaks to HTML
return $text;
}
?>
generate_text_for_storage
to a var so you canvar_dump
it. That might show you what happens – Hinkle