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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple eregi_replace problem

    I *suck* at writing replaces with variables - the syntax boggles my mind, so I was hoping someone here could help with this simple problem.

    Due to my laziness, on my new site, i've got an autolink function and a bbocde function - seems like no problem, I got the autolink to convert into BBCode which the BBCode parser then parses. however, when I type the following bbcode:

    Code:
    [ url=http://test.com]Test[/url]
    *it's supposed to be without the space, for some reason CODE tags parse it if I don't add in the space*

    This is the outcome:

    Code:
    [ url=[ url=http://test.com]http://test.com[/url]]Test[/url]
    *it's supposed to be without the space, for some reason CODE tags parse it if I don't add in the space*

    Can someone *please* write me a quick eregi replace which would change that (and all other URL bbcodes in that fashion), to this:
    Code:
    [ url=http://test.com]Test[/url]
    *it's supposed to be without the space, for some reason CODE tags parse it if I don't add in the space*

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    First rule is do NOT use eregi. It's deprecated as of 5.3.0 and completely removed in PHP6 onwards. The magical function you need is preg_replace
    PHP Code:
    $result preg_replace('%\[\s*url\s*=\s*([^\]]+?)\s*\](.*?)\[\s*/\s*url\s*\]%''<a href="$1">$2</a>'$subject); 
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I will start using preg, thanks, but that's not quite what I was after. i was looking to fix my URL tags, not add them. I just want to replace

    [url=[ url=The URL I'm linking to]The URL I'm linking to[/url]]The text that describes the link[/url]

    with

    [url=The URL I'm linking to]The text that describes the link[/url]


  •  

    Posting Permissions

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