Bbcodes On Websites

Pages: 1, 2
free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Bbcodes On Websites

galexcd
CODE
function url($url,$text=""){
$url=str_replace(array("<",">"),"",trim($url));
if(preg_match("/javascript(\:|\s)/i", $img) || empty($url)) return'<font size=2><i>Error: "'.$url.'" is invalid.</i></font>';
if($text=="")$text=$url;
return '<a href='.$url.'>'.$text.'</a>';
}
function bbReplace($string){
$string=preg_replace(
array('/\[center\](.*?)\[\/center\]/is','/\[right\](.*?)\[\/right\]/is','/\[youtube\](.*?)\[\/youtube\]/is'),
array('<center>$1</center>','<div style="align:right;">$1</div>','<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/$1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>'),
$string);
$string=preg_replace(
array('/\[url\=(.*?)\](.*?)\[\/url\]/ie','/\[email\](.*?)\[\/email\]/ie'),
array("url('$1','$2')","url('mailto:'.'$1','$1')"),
$string);
return $string;
}


So save this in a file or just add this snippet of code to the beginning of the file you want the bb-code parsing to happen.

This was written very quickly and haphazardly and was not tested so if you have any problems, just post them here.

 

 

 


Reply

demonlord
thank you i will give it a try and post back if i have any problems
when i tested this code i could not get it to work, why is this?

Reply

rvalkass
QUOTE(demonlord @ Mar 10 2008, 01:12 PM) *
when i tested this code i could not get it to work, why is this?


I assume you got an error message appear on the screen? It would be helpful if you could post the error messages, as that will lead us to the source of the error.

Reply

alex1985
Can I insert like the BB Code on my site, like the one on forums as well as on portals, just click the icons above the typing field, and it will do automatically?!

Reply

demonlord
no there was no error message it just gave me the tags that i put in the comment field when i submitted, it. i tryed using the center tag so in the comment fields i pu the following:
CODE
[center]this is a test to see if the bbcodes are working[/center]

and when it submitted the info, all i saw was what i put in the box center tags and all.

Reply

alex1985
So, how do I plug such BB Codes on my site's page?!

Reply

galexcd
Did you use the function I wrote? The function doesn't automatically parse it for you, you actually need to call it tongue.gif

instead of something like this:
CODE
echo mysql_result($result,0,"post");


Try this:
CODE
echo bbReplace(mysql_result($result,0,"post"));

Reply

alex1985
All right. How to integrate the complicated BB Code Parsing like the one on this forum, with pictures, a user just click the picture and the action will follow. You can take the quick form reply as an exemple for that.

Reply

rvalkass
Both the opening of the Fast Reply box, and the buttons for adding BBCodes work by using Javascript. The Fast Reply box is opened and closed by using HTML and CSS properties to display and hide elements. The Javascript just toggles between displaying the box, and not displaying it.

Getting the BBCodes inserted is a bit trickier, and notoriously hard to get working in IE, FF, Opera, Konqueror, Safari and all the other browsers. The code can get quite complex to work across all the browsers, and rather than try to write it myself and replicate it here, I'll point you to a Google search that contains many different ways of achieving this, each with their own pros and cons: http://www.google.co.uk/search?hl=en&q...earch&meta=

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for bbcodes, websites

*MORE FROM TRAP17.COM*
advertisement



Bbcodes On Websites



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE