12 Replies - 8283 Views - Last Post: 26 July 2009 - 07:47 AM Rate Topic: -----

#1 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Converting html to bbcode

Posted 22 July 2009 - 02:58 PM

ok so I found a function that allowed me to echo the bbcodes...now each one works apart for the url one:

function BBCODE($bbcode)
{
//the bbcode tags..
$bbc_a=array("[s]","[/s]","[b]","[/b]","[u]","[/u]","[i]","[/i]","[center]","[/center]","[small]","[/small]","[big]","[/big]","[huge]","[/huge]","[url]","[/url]","[red]","[/red]","[orange]","[/orange]","[green]","[/green]","[blue]","[/blue]");

//bbcode gets converted to..
$bbc_b=array("<s>","</s>","<b>","</b>","<u>","</u>","<i>","</i>","<center>","</center>","<small>","</small>","<font size=4>","</font>","<font size=8>","</font>","<a href=\"\">","</a>","<font color=#ff6666>","</font>","<font color=#ffaa66>","</font>","<font color=#66ff66>","</font>","<font color=#6666ff>","</font>");



this is the outcome I get atm:

[url="www.google.co.uk"]Google

Is This A Good Question/Topic? 0
  • +

Replies To: Converting html to bbcode

#2 TTechGuy  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 63
  • Joined: 24-April 09

Re: Converting html to bbcode

Posted 22 July 2009 - 03:27 PM

It looks like the url is used differently that your function expects. It appears to expect
[url]www.google.co.uk[/url]


and what is being sent is:
[url="ww.google.co.uk"]Google



you could change the first one from
$bbc_a=array("[s]","[/s]","[b]","[/b]","[u]","[/u]","[i]","[/i]","[center]","[/center]","[small]","[/small]","[big]","[/big]","[huge]","[/huge]","[url]","[/url]","[red]","[/red]","[orange]","[/orange]","[green]","[/green]","[blue]","[/blue]");

to 
$bbc_a=array("[s]","[/s]","[b]","[/b]","[u]","[/u]","[i]","[/i]","[center]","[/center]","[small]","[/small]","[big]","[/big]","[huge]","[/huge]","[url=","[/url]","[red]","[/red]","[orange]","[/orange]","[green]","[/green]","[blue]","[/blue]");


but that won't be exactly correct since it will not insert the web site name nor will it close the href correctly.
Was This Post Helpful? 0
  • +
  • -

#3 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: Converting html to bbcode

Posted 22 July 2009 - 03:39 PM

gave it a go but nothin...even tried [url=] but got nothin for that either
Was This Post Helpful? 0
  • +
  • -

#4 TTechGuy  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 63
  • Joined: 24-April 09

Re: Converting html to bbcode

Posted 22 July 2009 - 04:01 PM

This might be helpful. http://www.pixel2lif...showtopic=10659

Near the bottom is a function that takes care of the url=
Was This Post Helpful? 0
  • +
  • -

#5 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: Converting html to bbcode

Posted 22 July 2009 - 05:16 PM

cheers that function is so much better :)

and it gets what I want also :P

cheers techguy

[edit] quick question for some reason the url when i do the bbcode [url=www.google.co.uk] it shows on the status bar

www.mywebsite.com/Mafia/www.google.co.uk

anyone know why?

This post has been edited by Decypher: 22 July 2009 - 05:19 PM

Was This Post Helpful? 0
  • +
  • -

#6 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Converting html to bbcode

Posted 22 July 2009 - 10:10 PM

simple bbcode in php it will help you. :)
Was This Post Helpful? 0
  • +
  • -

#7 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Converting html to bbcode

Posted 22 July 2009 - 10:21 PM

or try this
<?php
function BBCODE($bbcode,$order)
{
//the bbcode tags..
$bbc_a=array("[s]","[/s]","[b]","[/b]","[u]","[/u]","[i]","[/i]","[center]","[/center]","[small]","[/small]","[big]","[/big]","[huge]","[/huge]","[url="http://",""]","[/url]","[red]","[/red]","[orange]","[/orange]","[green]","[/green]","[blue]","[/blue]");

//bbcode gets converted to..
$bbc_b=array("<s>","</s>","<b>","</b>","<u>","</u>","<i>","</i>","<center>","</center>","<small>","</small>","<font size=4>","</font>","<font size=8>","</font>","<a href=\"\">","</a>","<font color=#ff6666>","</font>","<font color=#ffaa66>","</font>","<font color=#66ff66>","</font>","<font color=#6666ff>","</font>");

if($order=="html") //change bbcode to html
{
$return = str_replace($bbc_a,$bbc_b,$bbcode);
}
elseif($order=="bbcode")//change html to bbcode
{
	$return = str_replace($bbc_b,$bbc_a,$bbcode);
}
	return $return;

}
echo BBCODE('<b>Chanage to bbcode</b>',"bbcode");
echo "<br />";
echo htmlspecialchars(BBCODE('[b]Change to HTML code[/b]','html'));
?>

This post has been edited by noorahmad: 22 July 2009 - 10:25 PM

Was This Post Helpful? 0
  • +
  • -

#8 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Converting html to bbcode

Posted 22 July 2009 - 10:26 PM

the bbc_a array is missing its value it is your own code bbc_a and bbc_b
Was This Post Helpful? 0
  • +
  • -

#9 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: Converting html to bbcode

Posted 23 July 2009 - 07:31 AM

apologies noorahmad...my code has changed from the top as Techguy found a better function...here's the code for the url bit:

	'@\[(?i)url=(.*?)\](.*?)\[/(?i)url\]@si',

converts to

	'<a href=\\1>\\2</a>'


Was This Post Helpful? 0
  • +
  • -

#10 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Converting html to bbcode

Posted 24 July 2009 - 11:13 PM

Glad you solved your problem :)
Was This Post Helpful? 0
  • +
  • -

#11 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Converting html to bbcode

Posted 25 July 2009 - 03:09 AM

If you don't include the protocol most browsers render the url as if it were relative to page it's included in. if you do: [url=http://www.google.co.uk] I think it would be just fine! :)

View PostDecypher, on 23 Jul, 2009 - 02:16 AM, said:

cheers that function is so much better :)

and it gets what I want also :P

cheers techguy

[edit] quick question for some reason the url when i do the bbcode [url=www.google.co.uk] it shows on the status bar

www.mywebsite.com/Mafia/www.google.co.uk

anyone know why?

Was This Post Helpful? 0
  • +
  • -

#12 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: Converting html to bbcode

Posted 26 July 2009 - 07:28 AM

ahh right cheers wimpy
Was This Post Helpful? 0
  • +
  • -

#13 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Converting html to bbcode

Posted 26 July 2009 - 07:47 AM

No problem, it's easy to forget those little things that might not be that obvious! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1