SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Showing Links with ereg_replace()

    Hi,
    this is a snippet pulled out of Kevin's book, but I'm having problems with URL's that contain "&" symbols...(and possibly more)

    PHP Code:
    $string ereg_replace(
      
    '\[L]([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\[/L]',
      
    '<a href="\\1">\\1</a>'$string);
    $string ereg_replace(
      
    '\[L=([-_./a-zA-Z0-9!&%#?+,\'=:~]+)]'.
      
    '([-_./a-zA-Z0-9 !&%#?+$,\'"=:;~]+)\[/L]',
      
    '<a href="\\1">\\2</a>'$string); 
    Whenever I type in something like

    Code:
    [L=http://www.polvero.com/boards/index.php?showtopic=116&st=30]Click Here[/L]
    into the database....it spits it out exactly as that onto the page. Even with the ereg_replace() shown above.
    See here for an example of where this happened.

    On the other hand, if it were something simpler like
    Code:
    [L=http://www.polvero.com/index.php?id=15]Click Here[/L]
    it would actually show up as a link.

  2. #2
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hi

    try with string replace!!!
    ereg and preg replace is out from years!!!
    cya
    Last edited by hyperimage; Feb 18, 2004 at 02:02.

  3. #3
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Um, stri_replace will only do straight replacing. It will not do regular expresions. I'm sure you meant use preg_replace instead of ereg_replace as it uses PCRE which is much faster. But that still doesn't answer his question. I'm sure one of the regular expression wizards will be arround shortly to help you.

  4. #4
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks fella's
    i'll look forward to it
    It really makes my code look bad when my site visitors are looking at BBcode in the middle of my articles.

  5. #5
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you looked at the user contributed notes for preg_replace on the php website? There is usually alot of url examples there.

  6. #6
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'll go and check those out

  7. #7
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out!
    Thank you all for your suggestions, you have been very helpful.
    A buddy of mine pointed out and asked if I had htmlspecialchars() anywhere in this script.
    In this case, it was "before" the snippet i posted. Thus I had to change it from this:
    PHP Code:
    $string ereg_replace
      
    '\[L]([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\[/L]'
      
    '<a href="\\1">\\1</a>'$string); 
    $string ereg_replace
      
    '\[L=([-_./a-zA-Z0-9!&%#?+,\'=:~]+)]'
      
    '([-_./a-zA-Z0-9 !&%#?+$,\'"=:;~]+)\[/L]'
      
    '<a href="\\1">\\2</a>'$string); 
    to this:

    PHP Code:
    $string ereg_replace
      
    '\[L]([-_./a-zA-Z0-9!&amp;%#?+,\'=:~]+)\[/L]'
      
    '<a href="\\1">\\1</a>'$string); 
    $string ereg_replace
      
    '\[L=([-_./a-zA-Z0-9!&amp;%#?+,\'=:~]+)]'
      
    '([-_./a-zA-Z0-9 !&%#?+$,\'"=:;~]+)\[/L]'
      
    '<a href="\\1">\\2</a>'$string); 

  8. #8
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh, that makes sense.


Bookmarks

Posting Permissions

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