SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Regular Expression Help Requested.

    I am using the method below to parse text from a database and convert links into actual hyperlinks ...
    PHP Code:
    $linkpattrn "/\b((http(s?):\/\/)|(www\.))([\w\.]+)([\/\w+\.]+)\b/i";
    $linkreplace "<a href=\"http$3://$4$5$6\" target=\"_blank\">$2$4$5$6</a>";
    $desc preg_replace ($linkpattrn$linkreplace$callrow->ProbDesc);
    $desc nl2br ($desc); 
    ... This works fine in almost all cases - except if the path has a space or %20 in it, in which case the hyperlink terminates at the first space (or %20). How can I amend $linkpattrn to cater for this?

    Regular expressions are not my strong point - as you can probably gather.
    Ian Anderson
    www.siteguru.co.uk

  2. #2
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    reg expressions are not my strongest point (at all

    But I did get some really good responses a bit back ...

    http://www.sitepointforums.com/showt...hreadid=103570

    I hope it helps ...
    the neigbours (free) WIFI makes it just a little more fun

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Not sure that's doing the same thing as I am after (it seems to be looking for existing <a> tags and checking them for putting in the target attribute) but thanks anyway for trying.
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can anyone else offer any ( clean ) suggestions? It's not life-threatening but any workable solutions would help advance my education in this area.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I guess the answer is no then, ah?
    Ian Anderson
    www.siteguru.co.uk

  6. #6
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about a str_replace %20 for a whitespace ?? or some other symbol..
    I know it sounds quick and dirty (esspecially the latter )
    the neigbours (free) WIFI makes it just a little more fun

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That might work - I could replace space and %20 with an obscure character (e.g. ), do the preg_match, then replace back to %20. Not the ideal approach though and I'm sure the change to $linkpattrn must be quite simple but I just can't quite see it.
    Ian Anderson
    www.siteguru.co.uk


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
  •