Welcome Guest ( Log In | Register)



2 Pages V  < 1 2  
Reply to this topicStart new topic
> Bbcodes On Websites
galexcd
post Mar 10 2008, 05:37 AM
Post #11


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********

Group: [HOSTED]
Posts: 1,189
Joined: 25-September 05
From: Los Angeles, California
Member No.: 12,251
myCENT:39.85



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.
Go to the top of the page
 
+Quote Post
demonlord
post Mar 10 2008, 01:12 PM
Post #12


Member [Level 3]
******

Group: [HOSTED]
Posts: 92
Joined: 1-January 08
Member No.: 55,554



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?

This post has been edited by demonlord: Mar 10 2008, 01:29 PM
Go to the top of the page
 
+Quote Post
rvalkass
post Mar 10 2008, 05:33 PM
Post #13


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,235
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol
myCENT:5.98



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.
Go to the top of the page
 
+Quote Post
alex1985
post Mar 10 2008, 05:38 PM
Post #14


Super Member
*********

Group: [HOSTED]
Posts: 397
Joined: 9-February 08
Member No.: 57,615



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?!
Go to the top of the page
 
+Quote Post
demonlord
post Mar 10 2008, 05:40 PM
Post #15


Member [Level 3]
******

Group: [HOSTED]
Posts: 92
Joined: 1-January 08
Member No.: 55,554



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.
Go to the top of the page
 
+Quote Post
alex1985
post Mar 10 2008, 05:58 PM
Post #16


Super Member
*********

Group: [HOSTED]
Posts: 397
Joined: 9-February 08
Member No.: 57,615



So, how do I plug such BB Codes on my site's page?!
Go to the top of the page
 
+Quote Post
galexcd
post Mar 10 2008, 06:29 PM
Post #17


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********

Group: [HOSTED]
Posts: 1,189
Joined: 25-September 05
From: Los Angeles, California
Member No.: 12,251
myCENT:39.85



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"));
Go to the top of the page
 
+Quote Post
alex1985
post Mar 24 2008, 08:03 AM
Post #18


Super Member
*********

Group: [HOSTED]
Posts: 397
Joined: 9-February 08
Member No.: 57,615



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.
Go to the top of the page
 
+Quote Post
rvalkass
post Mar 24 2008, 10:56 AM
Post #19


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,235
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol
myCENT:5.98



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=