Jump to content

[SOLVED] replacing bbcode with html tags using php


lilwing

Recommended Posts

hey guys, i am stuck.

 

i have a place for people to post with bbcode (written with javascript), the data is posted and sent to a mysql database, and retrieved from my website's page, where it is displayed.

 

when the data shows up on the page, the bbcode is still visible. is there a php script for this? if there is where would i put it? on the website's page?

There are many script's out there to do this.

It's actually very simple to make it.

 

Example to take [ b] to < b>.

<?php
function bbcode($String){
if (empty($string)){
return false; 
}
$String = srt_replace("[b]","<b>",$String);
return $String;
}
?>

it's not working. i probably did something wrong. for example:

 


 function bbcode($String){
if (empty($string)){
return false; 
}
$String = srt_replace("[b]","<b>",$String);
return $String;
}

$host="localhost"; // Host name
$username="bleep"; // Mysql username
$password="bleep"; // Mysql password
$db_name="bleep"; // Database name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql = "SELECT * FROM headlines ORDER BY id DESC LIMIT 2";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
$current = $row['pagecontent'];
bbcode($current);
echo $current;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.