SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
-
Jun 2, 2003, 07:46 #1
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- 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);
Regular expressions are not my strong point - as you can probably gather.
-
Jun 2, 2003, 07:55 #2
- 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
-
Jun 2, 2003, 08:03 #3
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- 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.
-
Jun 3, 2003, 04:11 #4
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- 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.
-
Jun 4, 2003, 02:42 #5
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
I guess the answer is no then, ah?
-
Jun 4, 2003, 04:14 #6
- 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
-
Jun 4, 2003, 05:51 #7
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- 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.
Bookmarks