473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

Aug 8 '06 #1
5 1681
monomaniac21 wrote:
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

Aug 8 '06 #2
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:
monomaniac21 wrote:
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
Aug 8 '06 #3
$para1 = implode(' ', $para1);
should be : $para1 = implode(' ', $newarr);

oops!

Aug 8 '06 #4
"monomaniac21" <mc******@googlemail.comwrote:
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
Aug 8 '06 #5
Rik
Miguel Cruz wrote:
"monomaniac21" <mc******@googlemail.comwrote:
>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
Aug 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Badboy36 | last post by:
Hello user from googlegroups, i made a microsoft access database with front and backend. i created the backend in microsoft access97. for the frontend i made two versions (one for microsoft...
0
by: Ryan Harvey | last post by:
Hi all, I have written a web user control that contains a repeater control. the ItemTemplate for this control is basically 6 Hyperlinks in a row, that are dynamically allocated one of 7 gif...
9
by: Leon | last post by:
What Am I Doing Wrong? Code Will Not Run, I Can't See The Error! Thanks. <asp:datalist id="DataList1" runat="server" RepeatColumns="4"> <ItemTemplate> <asp:HyperLink id=HyperLink1 ImageUrl=...
10
by: david | last post by:
Hi, all: I need a help from you about DataGrid control. I created a DataGrid, dg, in design view of .NET visual Stadio and use the builder to add a Hyperlink column to dg. I want to try to assign...
19
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred...
8
by: Nathan Sokalski | last post by:
I have several System.Web.UI.WebControls.HyperLink Controls which I want to display as rollover images. I know how to make these manually using the <a> and <img> tags or the <a> tag and a...
20
by: tshad | last post by:
I had posted this problem earlier and just noticed that the Hyperlink is the problem. Apparently, it doesn't figure out the path correctly. It uses the path of the file it is in, even if it is...
2
by: rjoseph | last post by:
Hi Guys I hope this is a simple one for you. I am basically displaying data onto my xml page using the following line of code: <xsl:value-of select="carmanufacturer" /> An example of the...
10
by: sierra7 | last post by:
I'm trying to create a form where a user enters a document reference number and then clicks a command button to add a hyperlink to the document, via a file picker. Thanks to Adezii's excellent...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.