Jump to content

BBCodes


Anders Moen

Recommended Posts

And how do I insert it?This is how some of the rest looks:$tekst = str_replace("[*code]", "<div style='background-color: #f2f0e7;'>", $tekst);$tekst = str_replace("[/code*]", "</div>", $tekst); // without the stars of course :) I didn't excactly get what you meant then. So can you use the whole thing?

Link to comment
Share on other sites

Dont know if this helps or if this is what you want but :

function rep2($tekst) {$tekst = str_replace('<','<',$tekst);$tekst = str_replace('>','>',$tekst);$tekst = str_replace('"','\"',$tekst);$tekst = str_replace(''',"'",$tekst);$tekst = str_replace('amp;','&',$tekst);return $tekst;}

Just copyed now :) so just take the function content and insert into the code i gave you if you still use it, if not i cant help you. ->Kristian_C.

Link to comment
Share on other sites

I know, but I just don't have time enough to read all that stuff. I wish I had though =/We have way too much to homework and stuff...Oh well, I'll try to get some time so I can read it soon :)

Link to comment
Share on other sites

  • 2 weeks later...

I have anotther question ,I just want to make sure php dosen't switch by doing this:' -> \' and \ -> \\and I want than the text to be writen in a new file...my code to do so is this:

function fix($texte) {$texte = str_replace('<','<',$texte);$texte = str_replace('>','>',$texte);$texte = str_replace('"','\"',$texte);$texte = str_replace('\'', '\\\'',$texte);$texte = str_replace('\\', '\\\\',$texte);$texte = str_replace('amp;','&',$texte);return $texte;}//etc...$fh = fopen("my_page.htm", 'w') or die("It didn't work!');fwrite($fh,"".fix($ftexte."");fclose($fh);//$texte is already set above but he content of it dosen't matter...

Link to comment
Share on other sites

justsomeguy > Thanks a lot I was stuck on it for days... Ican't beleive I didn't see that stupid error.andersmoen > Did you try-it like this?

<?php$con = mysql_connect("localhost","username","password");if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("database", $con);function bbcode($tekst){// Alignment of a text:$tekst = str_replace("[center]", "<div align='center'>", $tekst);$tekst = str_replace("[/center]", "</div>", $tekst);$tekst = str_replace("[left]", "<div align='left'>", $tekst);$tekst = str_replace("[/left]", "</div>", $tekst);$tekst = str_replace("[right]", "<div align='right'>", $tekst);$tekst = str_replace("[/right]", "</div>", $tekst);//So for spaceing you will need something like this :$tekst = str_replace(array("\r\n", "\n", "\r"), '<br>', $tekst); //To create a link of the type [url=http://www.w3schools.com/]W3schools[/url]$tekst= str_replace("[url=","<a  location='blank' href='",$tekst);$tekst= str_replace("]","' >",$tekst);$tekst= str_replace("[/url]","</a>",$tekst);// If You Want to add an image too:$tekst= str_replace("[img=","<img src='",$tekst);$tekst= str_replace("]","' />",$tekst);// Underline, bold and Italic text:$tekst= str_replace("[b]","<strong>",$tekst);$tekst= str_replace("[/b]","</strong>",$tekst);$tekst= str_replace("[i]","<i>",$tekst);$tekst= str_replace("[/i]","</i>",$tekst);$tekst= str_replace("[u]","<u>",$tekst);$tekst= str_replace("[/u]","</u>",$tekst);// Set the color of a text:$tekst= str_replace("[color=","<font color='",$tekst); //closing this tag is set for [url]$tekst= str_replace("[/color]","</a>",$tekst);return $tekst;}$result = mysql_query("SELECT * FROM table ORDER BY `id` DESC LIMIT 0, 10");while($row = mysql_fetch_array($result)){echo "<div style='color: black; background-color: lightgreen; padding: 2px; border: 1px solid lightgreen;'>";echo "<div style='width: 70px; float: left;'>";echo "<a href='mailto:".$row[email]."'>".$row[navn]."</a>";echo "</div>";echo "<div style='width: 68px; float: right;'>";echo $row[dato];echo "</div>";echo "<br />";echo "<br />";$kommentar = bbcode($row[kommentar]);echo $kommentar;echo "</div>";echo "<br />";echo "<br />";}mysql_close($con);?>

Thibo_1025

Link to comment
Share on other sites

Yeah. That's how I've tried it, but when I add on that strip_tags thing, the other things there doesn't work :S Then it just shows XHTML in the browser like at learning sites like W3Schools (in their examples). For example, if someone types text it works fine for me. But when I put on strip_tags to make them not ###### up my site by for example adding <html><head><title>lol</title></head><body>HAHAH</body></html> so I get it twice and it's not Valid XHTML 1.1 anymore.

THIS IS MY POST 200

Link to comment
Share on other sites

Actually, you can just forget the whole thing :)Because someone I know from Sweden sent me a much more advanced one, that actually works like I want it to :)I can post it later. I have to find it first lol. My messy computer :)

Link to comment
Share on other sites

  • 2 weeks later...

otherwise I have a problem...I have Two functions:

//Function to fix php errors.function fix($tekst) {$tekst = str_replace("<","<",$tekst);$tekst = str_replace(">",">",$tekst);$tekst = str_replace('"','\"',$tekst);$tekst = str_replace("\'", "'",$tekst);$tekst = str_replace("\\", "\\",$tekst); // I know that one is useless but it sorts aout fine like this.$tekst = str_replace("amp;","&",$tekst);return $tekst;}

and

//BBcode function.function bbcode($tekst){// Alignment of a text:$tekst = str_replace("[center]", "<div align='center'>", $tekst);$tekst = str_replace("[/center]", "</div>", $tekst);$tekst = str_replace("[left]", "<div align='left'>", $tekst);$tekst = str_replace("[/left]", "</div>", $tekst);$tekst = str_replace("[right]", "<div align='right'>", $tekst);$tekst = str_replace("[/right]", "</div>", $tekst);//So for spaceing you will need something like this :$tekst = str_replace(array("\r\n", "\n", "\r"), '<br>', $tekst); //To create a link of the type [url=http://www.w3schools.com/]W3schools[/url]$tekst= str_replace("[url=","<a  location='blank' href='",$tekst);$tekst= str_replace("]","' >",$tekst);$tekst= str_replace("[/url]","</a>",$tekst);// If You Want to add an image too:$tekst= str_replace("[img=","<img src='",$tekst);$tekst= str_replace("]","' />",$tekst);// Underline, bold and Italic text:$tekst= str_replace("[b]","<strong>",$tekst);$tekst= str_replace("[/b]","</strong>",$tekst);$tekst= str_replace("[i]","<i>",$tekst);$tekst= str_replace("[/i]","</i>",$tekst);$tekst= str_replace("[u]","<u>",$tekst);$tekst= str_replace("[/u]","</u>",$tekst);// Set the color of a text:$tekst= str_replace("[color=","<font color='",$tekst); //closing this tag is set for [url]$tekst= str_replace("[/color]","</a>",$tekst);return $tekst;}

And I send a text from a form to a file.how should I do it?

fwrite($fh, bbcode(fix($tekst)));

or

fwrite($fh, fix(bbcode($tekst)));

Link to comment
Share on other sites

Hey!I went to BBCode.org, and there I found these BBCodes, and they work fine.I just add them in a file called bbcode.php (just example), and then on the site I need them<?phpinclude('bbcode.php');while{echo bbcode($row['name']);}?>And this works just fine :)You can try it here

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...