Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 8th, 2006, 01:35 PM
monomaniac21
Guest
 
Posts: n/a
Default replacing www... with hyperlink

hi all i want to replace all entries of beginning with 'www.' and
ending with ' ' with a hyperlink to that substring such as:

www.google.com := <a href="www.google.com">www.google.com</>

can anyone tell me the easiest way to do this?

regards

marc

  #2  
Old August 8th, 2006, 01:55 PM
Ciaran
Guest
 
Posts: n/a
Default Re: replacing www... with hyperlink

monomaniac21 wrote:
Quote:
hi all i want to replace all entries of beginning with 'www.' and
ending with ' ' with a hyperlink to that substring such as:
>
www.google.com := <a href="www.google.com">www.google.com</>
>
can anyone tell me the easiest way to do this?
You'll want to put an 'http://' in the href attribute, too.

The best way to do this is to use preg_replace, see the manual at
http://php.net/preg_replace.

-Ciaran

  #3  
Old August 8th, 2006, 03:35 PM
monomaniac21
Guest
 
Posts: n/a
Default Re: replacing www... with hyperlink

well i figured out my own way of doing this cos the problem kept
bugging me and ive added her for anyone else who is interested. if
anyone else knows of a more efficient way id love to hear it. im not
sure but i think exploading a string then searching each array value
might be bettered by a function that just performed a search and
replace on the string.

$para1 = "sdfsdf dsf dsfsd www.dsafads.com";
$para1_arr = explode(' ',$para1);
$i = 0;
foreach ($para1_arr as $value) {
$newarr[$i] = $value;
if (strstr($value, 'www.') != FALSE) {
$value = "<a href='http://$value'>$value</a>";
$newarr[$i] = $value;
}
$i = $i + 1;
}
$para1 = implode(' ', $para1);




Ciaran wrote:
Quote:
monomaniac21 wrote:
Quote:
hi all i want to replace all entries of beginning with 'www.' and
ending with ' ' with a hyperlink to that substring such as:

www.google.com := <a href="www.google.com">www.google.com</>

can anyone tell me the easiest way to do this?
>
You'll want to put an 'http://' in the href attribute, too.
>
The best way to do this is to use preg_replace, see the manual at
http://php.net/preg_replace.
>
-Ciaran
  #4  
Old August 8th, 2006, 03:45 PM
monomaniac21
Guest
 
Posts: n/a
Default Re: replacing www... with hyperlink

Quote:
$para1 = implode(' ', $para1);
should be : $para1 = implode(' ', $newarr);

oops!

  #5  
Old August 8th, 2006, 05:05 PM
Miguel Cruz
Guest
 
Posts: n/a
Default Re: replacing www... with hyperlink

"monomaniac21" <mcyi2mr3@googlemail.comwrote:
Quote:
well i figured out my own way of doing this cos the problem kept
bugging me and ive added her for anyone else who is interested. if
anyone else knows of a more efficient way id love to hear it. im not
sure but i think exploading a string then searching each array value
might be bettered by a function that just performed a search and
replace on the string.
>
$para1 = "sdfsdf dsf dsfsd www.dsafads.com";
$para1_arr = explode(' ',$para1);
$i = 0;
foreach ($para1_arr as $value) {
$newarr[$i] = $value;
if (strstr($value, 'www.') != FALSE) {
$value = "<a href='http://$value'>$value</a>";
$newarr[$i] = $value;
}
$i = $i + 1;
}
$para1 = implode(' ', $para1);
How will that work with mail.yahoo.com or groups.google.com ?

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
  #6  
Old August 8th, 2006, 05:45 PM
Rik
Guest
 
Posts: n/a
Default Re: replacing www... with hyperlink

Miguel Cruz wrote:
Quote:
"monomaniac21" <mcyi2mr3@googlemail.comwrote:
Quote:
>well i figured out my own way of doing this cos the problem kept
>bugging me and ive added her for anyone else who is interested. if
>anyone else knows of a more efficient way id love to hear it. im not
>sure but i think exploading a string then searching each array value
>might be bettered by a function that just performed a search and
>replace on the string.
>>
>$para1 = "sdfsdf dsf dsfsd www.dsafads.com";
>$para1_arr = explode(' ',$para1);
>$i = 0;
>foreach ($para1_arr as $value) {
>$newarr[$i] = $value;
>if (strstr($value, 'www.') != FALSE) {
>$value = "<a href='http://$value'>$value</a>";
>$newarr[$i] = $value;
>}
>$i = $i + 1;
>}
>$para1 = implode(' ', $para1);
>
How will that work with mail.yahoo.com or groups.google.com ?
Not, but as the OP stated: he only wants links beginning with www.
Personally, I'd check for '|[a-z]+://|', which will find protocols, and
maybe put an extra check in for words starting with 'www.'.

Grtz,
--
Rik Wasmus


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles