Jump to content

[SOLVED] bbcode question,,


stelthius

Recommended Posts

Ok so to be  short and sweet im using this for my bbcode and it all works fine other than link i cant seem to get link to work for some odd reason it keeps printing out plain html

 

 

<?php
function parseBB($text)
{
$pattern[0] = "/\[b\](.*?)\[\/b\]/is";		// Bold
$pattern[1] = '/\[i\](.*?)\[\/i\]/is';		// Italic
$pattern[2] = '/\[u\](.*?)\[\/u\]/is';		// Underline
$pattern[3] = '/\[url\](.*?)\](.*?)\[\/url\]/is';	// Link
$pattern[4] = '/\[img\](.*?)\[\/img\]/is';		// Image
$pattern[5] = '/\[color=(.*?)](.*?)\[\/color\]/is';	// Color

$replace[0] = "<span style='font-weight: bold;'>$1</span>";
$replace[1] = "<span style='font-style: italic;'>$1</span>";
$replace[2] = "<span style='text-decoration: underline;'>$1</span>";
$replace[3] = "<a href='$1'>$2</a>";
$replace[4] = "<img src='$1' />";
$replace[5] = "<span style='color: $1;'>$2</span>";

$text = preg_replace($pattern, $replace, $text);

return $text;
}
?>

 

Any ideas are greatly appretiated.

 

*EDIT* sorry forgot to mention i also have tried oing it this way

 

<?php
function parseBB($text)
{
$pattern[0] = "/\[b\](.*?)\[\/b\]/is";		// Bold
$pattern[1] = '/\[i\](.*?)\[\/i\]/is';		// Italic
$pattern[2] = '/\[u\](.*?)\[\/u\]/is';		// Underline
$pattern[3] = '/\[url=http://(.*?)\](.*?)\[\/url\]/is';	// Link
$pattern[4] = '/\[img\](.*?)\[\/img\]/is';		// Image
$pattern[5] = '/\[color=(.*?)](.*?)\[\/color\]/is';	// Color

$replace[0] = "<span style='font-weight: bold;'>$1</span>";
$replace[1] = "<span style='font-style: italic;'>$1</span>";
$replace[2] = "<span style='text-decoration: underline;'>$1</span>";
$replace[3] = "<a href='$1'>$2</a>";
$replace[4] = "<img src='$1' />";
$replace[5] = "<span style='color: $1;'>$2</span>";

$text = preg_replace($pattern, $replace, $text);

return $text;
}
?>

Link to comment
Share on other sites

Hello Garethp,

 

im using

 

<a title="Bold : [url\=[/url]" onmousedown="addTags(\'[url\=\',\'[/url]\')" style="background-color:#F7F7F7; font-size:10pt; border: outset white 1px;"> <b>URL</b> </a>

 

To insert my code i've just tried what you said but it still prints out

 

[url=link test[/url]

in the PM am i doing something wrong maybe im putting the bbcode tag into the JS button wrong ?

Link to comment
Share on other sites

If you try

[url=http://Google.com]Google[/url]

 

With

$pattern[3] = '/\[url=http://http:\/\/(.*?)\](.*?)\[\/url\]/is';

 

Then it works

 

However, you may want to change

$replace[3] = "<a href='$1'>$2</a>";

 

to

$replace[3] = "<a href='http://$1'>$2</a>";

 

Otherwise the link won't lead off your site

Link to comment
Share on other sites

Yes i understand all that clearly i made a mistake with my replacement vars, but with it still printing out as html its got to be my button that im doing wrong..

<a title="Bold : [url\=[/url]" onmousedown="addTags(\'[url\=\',\'[/url]\')" style="background-color:#F7F7F7; font-size:10pt; border: outset white 1px;"> <b>URL</b> </a>

 

Sorry if i seem dull first time using BBcode and JS to insert into textarea, Also thanks for your help & time its appretiated.

Link to comment
Share on other sites

Ok when i type in my URL and then wrap it with the URL tags i get

 

[url=www.google.co.uk[/url]

< Is what it looks like in the text area before i continue to send the message to user X

 

Now this is whats confusing me as ive seen lots of places using the URL tag that make it look like that...

Link to comment
Share on other sites

well i figured using

<a title="Bold : [url\=[/url]" onmousedown="addTags(\'[url\=\',\'[/url]\')" style="background-color:#F7F7F7; font-size:10pt; border: outset white 1px;"> <b>URL</b> </a>

would be the correct way t do it but im wrong so it seems.. ill continue to tr and work it out thanks for the help

Link to comment
Share on other sites

This works fine as im using it to insert bold, italic, underline and image tags and they work perfectly, maybe im wrong and missed something out..

 

<script language="JavaScript" type="text/JavaScript">

function addText(Text)
{
var obj = document.send.message;
obj.focus();

if (document.selection && document.selection.createRange) // Internet Explorer
{
sel = document.selection.createRange();
if (sel.parentElement() == obj) sel.text = Text;
}

else if (obj != "undefined") // Firefox
{
var longueur = parseInt(obj.textLength);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0,selStart) + Text + obj.value.substring(selEnd,longueur);
}

else obj.value += Text;

obj.focus();
}

function addTags(Tag, fTag)
{
var obj = document.send.message;
obj.focus();

if (document.selection && document.selection.createRange) // Internet Explorer
{
sel = document.selection.createRange();
if (sel.parentElement() == obj) sel.text = Tag + sel.text + fTag;
}

else if (obj != "undefined") // Firefox
{
var longueur = parseInt(obj.textLength);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0,selStart) + Tag + obj.value.substring(selStart,selEnd) + fTag + obj.value.substring(selEnd,longueur);
}

else obj.value += Tag + fTag;

obj.focus();
}

</script>

Link to comment
Share on other sites

Here's your problem

 

if (sel.parentElement() == obj) sel.text = Tag + sel.text + fTag;

 

A) You have two variables, while sel.text is only one

 

B) fTag is

[/url]

Not

]Link[/url]

Change

[code]
onmousedown="addTags(\'[url\=\',\'[/url]\')"

To

onmousedown="addTags(\'[url\=\',\']Link[/url]\')"

Link to comment
Share on other sites

I tried something similair to that earlier and it gave me

 

Warning: preg_replace() [function.preg-replace]: Unknown modifier '/' in /home/phpcorec/public_html/classes/bbcode.class.php on line 18

 

the same as its just given me now when i replaced

 

onmousedown="addTags(\'[url\=\',\'[/url]\')"

 

with

 

onmousedown="addTags(\'[url\=\',\']Link[/url]\')"

 

 

Link to comment
Share on other sites

Here is my current BBcode PHP file, changes made as suggested by you,

 

<?php
function parseBB($text)
{
$pattern[0] = "/\[b\](.*?)\[\/b\]/is";					// Bold
$pattern[1] = '/\[i\](.*?)\[\/i\]/is';					// Italic
$pattern[2] = '/\[u\](.*?)\[\/u\]/is';					// Underline
$pattern[3] = '/\[url=http://http:\/\/(.*?)\](.*?)\[\/url\]/is';	// Link
$pattern[4] = '/\[img\](.*?)\[\/img\]/is';				// Image
$pattern[5] = '/\[color=(.*?)](.*?)\[\/color\]/is';			// Color

$replace[0] = "<span style='font-weight: bold;'>$1</span>";
$replace[1] = "<span style='font-style: italic;'>$1</span>";
$replace[2] = "<span style='text-decoration: underline;'>$1</span>";
$replace[3] = "<a href='http://$1'>$2</a>";
$replace[4] = "<img src='$1' />";
$replace[5] = "<span style='color: $1;'>$2</span>";

$text = preg_replace($pattern, $replace, $text);

return $text;
}
?>

Link to comment
Share on other sites

Here's your problem

$pattern[3] = '/\[url=http://http:\/\/(.*?)\](.*?)\[\/url\]/is';
[code]

Has to become
[code]
$pattern[3] = '/\[url=http:\/\/(.*?)\](.*?)\[\/url\]/is';

 

You added another http:// which would have caused a problem in the first place, and you forgot to put a \ infront of the /'s. The one I gave you should work

Link to comment
Share on other sites

If you try

[url=http://Google.com]Google[/url]

 

With

$pattern[3] = '/\[url=http://http:\/\/(.*?)\](.*?)\[\/url\]/is';

 

Sorry i copied exactly what you said i guess i should have realised you didnt mean to type http:// two times, but, none the less thanks for the help as it is now working fully. thank you, no chocolate for you tho email wont send it hehe

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.