| View previous topic :: View next topic |
| Author |
Message |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Mon Dec 29, 2008 2:15 pm Post subject: bbcode problem [PHP] |
|
|
i'm adding bbcode to a forum i'm working on
the
ones are the ones i'm having trouble with
here is my code for them
| Code: | "[url]" => "<a href=>",
"[/url]" => "</a>" |
but it goes to the same page
any ideas???????
and i know...... I NEED TO LEARN 2 GRAMMAR
Last edited by deleted user 111213 on Mon Dec 29, 2008 3:01 pm; edited 2 times in total |
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Mon Dec 29, 2008 2:22 pm Post subject: |
|
|
| Look at the "target" parameter. |
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Mon Dec 29, 2008 2:26 pm Post subject: |
|
|
| i know about that, but what should i change it to? |
|
| Back to top |
|
 |
LolSalad Grandmaster Cheater
Reputation: 1
Joined: 26 Aug 2007 Posts: 988 Location: Australia
|
|
| Back to top |
|
 |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Mon Dec 29, 2008 7:23 pm Post subject: |
|
|
Erm, thats not how you do bbcode. If your making a forum or just adding bbcode, I suggest learning PHP first. _________________
| qwerty147 wrote: |
| ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Tue Dec 30, 2008 12:20 am Post subject: |
|
|
| ElectroFusion wrote: | | Erm, thats not how you do bbcode. If your making a forum or just adding bbcode, I suggest learning PHP first. |
Well since you're just "that good" at PHP. Why don't you actually help him instead of making some smart-ass rejoe. If you actually smart (which i doubt) then why don't you fucking help. _________________
Blog
| Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Tue Dec 30, 2008 3:22 am Post subject: |
|
|
| i have actually learnt php, i'm just not that brilliant at it. i could borrow that book of my mate, but he lives 100 miles away, and hes the only other guy i know who knows php. and im not joking about the 100 miles away bit. |
|
| Back to top |
|
 |
compactwater I post too much
Reputation: 8
Joined: 02 Aug 2006 Posts: 3923
|
Posted: Tue Dec 30, 2008 10:11 am Post subject: |
|
|
Your code would do this:
| Code: | [url]http://www.google.com/[/url]
<a href=>http://www.google.com/</a> |
I assume you want something like this:
| Code: | [url=http://www.google.com/]Click here[/url]
<a href="http://www.google.com">Click here</a>
--or--
[url]http://www.google.com/[/url]
<a href="http://www.google.com/">http://www.google.com/</a> |
Only the second would be possible with how you have it setup currently.
Fix:
| Code: | "[url]" => "<a href=\"",
"[/url]" => "\">$link</a>" |
Assuming $link contains the link.
However, a better option may be using preg_match/replace. |
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Tue Dec 30, 2008 10:27 am Post subject: |
|
|
| that code you gave me, didnt work. the posts wouldn't show up.(the ones with links in anyway) |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Dec 30, 2008 1:20 pm Post subject: |
|
|
| Code: | <?php
$string = "[url=http://www.google.com]lolwutgoogle[/url]";
$bbed = preg_replace('/\[url\=(.+)\](.+)\[\/url\]/', '<a href="$1">$2</a>', $string);
echo $bbed;
?> |
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Tue Dec 30, 2008 1:36 pm Post subject: |
|
|
| Reak wrote: | | Code: | <?php
$string = "[url=http://www.google.com]lolwutgoogle[/url]";
$bbed = preg_replace('/\[url\=(.+)\](.+)\[\/url\]/', '<a href="$1">$2</a>', $string);
echo $bbed;
?> |
|
could you possibly make it like,
| Code: | $BBCode = array("&" => "&",
"<" => "<",
">" => ">",
"[b]" => "<b>",
"[/b]" => "</b>",
"[i]" => "<i>",
"[/i]" => "</i>",
"[u]" => "<u>",
"[/u]" => "</u>",
"[img]" => "<img src='",
"[/img]" => "'>",
"[code]" => "<font style=\"padding:3px;\" color=\"#CC0000\" size=\"2\">Code:</font><br><div id='code'><tt>",
"[/code]" => "</tt></div>"); |
but like just "[url]" so it fits into my array? |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Dec 30, 2008 1:47 pm Post subject: |
|
|
Get a rid of string_replace or whatever you use.
| Code: | <?php
$pregs = array(
'/\[b\](.+)\[\/b\]/' => '<b>$1</b>',
'/\[i\](.+)\[\/i\]/' => '<em>$1</em>',
'/\[url\=(.+)\](.+)\[\/url\]/' => '<a href="$1">$2</a>'
);
$bold = preg_replace(array_keys($pregs), array_values($pregs), '[b]This is bold[/b]<br />');
$italic = preg_replace(array_keys($pregs), array_values($pregs), '[i]This is italic[/i]<br />');
$url = preg_replace(array_keys($pregs), array_values($pregs), '[url=http://www.google.de]This is an url[/url]<br />');
echo $bold.$italic.$url;
?> |
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Tue Dec 30, 2008 1:53 pm Post subject: |
|
|
i mean like in the same format i have done mine in
so like
| Code: | "[url]" => "<a href=>",
"[/url]" = > "</a>" |
but what do i put in between the <a href> bit? |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Dec 30, 2008 3:05 pm Post subject: |
|
|
Yea I know what you meant.
But you should get a rid of str_replace and use the code I posted.
It's much better.
I already added [i] and [b], so you can simply add other bbcodes like [u] or [img].. |
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Tue Dec 30, 2008 3:12 pm Post subject: |
|
|
how do i change [url= to just [url] please. thx for the code. but the [url= thing is annoying to use for me.
edit:also that kind of code is annoying. hard to edit. plus i dont know how to modify it into user input. ill show you my whole function.
2nd edit: that code doesn't work for me. it turns my website all wierd. so please use the array and function i supplied below the sentence. cause i have i tried that stuf and it has never worked for me.
| Code: | function topic($input){
$BBCode = array("&" => "&",
"<" => "<",
">" => ">",
"[b]" => "<b>",
"[/b]" => "</b>",
"[i]" => "<i>",
"[/i]" => "</i>",
"[u]" => "<u>",
"[/u]" => "</u>",
"[img]" => "<img src='",
"[/img]" => "'>",
"[code]" => "<font style=\"padding:3px;\" color=\"#CC0000\" size=\"2\">Code:</font><br><div id='code'><tt>",
"[/code]" => "</tt></div>",
"[url]" => "<a href=>",
"[/url]" => "</a>");
$parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $input);
return nl2br($parsedtext);
return nl2br(strip_tags(stripslashes(htmlspecialchars($input))));
} |
|
|
| Back to top |
|
 |
|