PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
GodOfHonk
Forum Newbie
Posts: 6 Joined: Thu May 09, 2002 2:17 pm
Location: St. Louis
Post
by GodOfHonk » Thu Sep 12, 2002 3:03 pm
Hello,
I have a regular expression that matched URLs and turns them into links. I now need to make sure this happens only if the URL is NOT enclosed in square brackets.
So the url for yahoo would be rendered as a link here:
Code: Select all
http://www.yahoo.com is a search engine
But not here:
Code: Select all
їhttp://www.yahoo.com] is a search engine
Here's the regexp I'm using so far:
Code: Select all
$Text = preg_replace("/(ї\w]+:\/\/ї\w-?&;#~=\.\/\@]+ї\w\/])/i", "<a href="$1">$1</a>", $Text);
Any ideas? Thanks in advance!!
Takuma
Forum Regular
Posts: 931 Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:
Post
by Takuma » Fri Sep 13, 2002 4:43 pm
You could just use
Code: Select all
&lt;?php
if(strstr($string,"ї")) {
echo "'ї' found!";
}
?&gt;
dusty
Forum Contributor
Posts: 122 Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA
Post
by dusty » Sat Sep 14, 2002 1:36 am
i don't see how that would help. it's only locating the [ but not replacing the urls w/o [] with a link.
Code: Select all
$text = preg_replace("/(?<!\ї)(http:\/\/)(ї\S\.]+)\b/i","<a href="http://$2$3$4">$1$2$3$4</a>", $text);
should skip [http://*] and link http://*
GodOfHonk
Forum Newbie
Posts: 6 Joined: Thu May 09, 2002 2:17 pm
Location: St. Louis
Post
by GodOfHonk » Sun Sep 15, 2002 12:34 am
Excellent!
Got it working, Thanks!!
-GodOfHonk
Takuma
Forum Regular
Posts: 931 Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:
Post
by Takuma » Sun Sep 15, 2002 3:14 am
dusty wrote: i don't see how that would help. it's only locating the [ but not replacing the urls w/o [] with a link.
Code: Select all
$text = preg_replace("/(?<!\ї)(http:\/\/)(ї\S\.]+)\b/i","<a href="http://$2$3$4">$1$2$3$4</a>", $text);
should skip [http://*] and link http://*
It does
Code: Select all
<?php
if(!strstr($string,"ї")) {
$Text = preg_replace("/(ї\w]+:\/\/ї\w-?&;#~=\.\/\@]+ї\w\/])/i", "<a href="$1">$1</a>", $Text);
} else {
return false;
}
?>
dusty
Forum Contributor
Posts: 122 Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA
Post
by dusty » Sun Sep 15, 2002 10:49 am
that makes no sense to me..all you're doing is finding an occurence of [ in the string.
"[ before
http://www.yahoo.com " would be skipped
just makes no sense to use strstr in this situation.