Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    BBCode in PHP...

    I am creating a comment system.

    I have got the basic BBCode stuff down like bold, italics, underline and coloured.

    But the thing I am having trouble with is the 'url' code.

    The code for the 'url' tag is below...
    PHP Code:
    $Text preg_replace ('/\[url\=(.*?)\](.*?)\[\/url\]/is''<a href="$1">$2</a>'$Text); 
    When I tested it, it just seems to place my website address before the typed in address like so...
    Code:
    http://www.mywebsite/typedinaddress
    How could I fix this problem?

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Are you supplying an http with the typed in address? If you fail to do that, the browser will assume it's a link to a local document - even if you DO have a www. Because of that it'll just concatenate whatever you typed in to the current address in the address bar.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #3
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    PHP has libraries to do bbcode for you.
    http://us.php.net/manual/en/book.bbcode.php

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by malfist View Post
    PHP has libraries to do bbcode for you.
    http://us.php.net/manual/en/book.bbcode.php
    That's a PECL extension. A user on a shared server more than likely wouldn't be able to use it. The installation page suggests an alternative PEAR library that could be used, but it's still probably easier to write your own if you're familiar with regular expressions; specifically Perl-compatible.

  • #5
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    How is adding a PEAR library harder than writing a parser?

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Like I said, if you're familiar with regular expressions it would be easier to write your own than install a third-party module or class that you don't understand how it works. You don't have to worry about the author updating it, and you can make whatever changes you want whenever you want. You can also limit(or expand) the scope of the replacements to the tags you want or need, not the ones that someone else deems necessary.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •