I have a string with the following information.
$myString = "This is my example string please. Please visit http://www.mylink.com . More example text goes here. another link http://www.link2.com . more text.. blah..";
What I'm wanting is a function to return the following string :
$myString = This is my example string please. Please visit <a
href'http://www.mylink.com' >link</a> . More example text goes here.
another link <a href='http://www.link2.com'> link</a> . more text.. blah..";
Each string may contain 0 or more http:// instances. The function would
only parse on an http:// match.
I know this could be done with regular expressions, but I'm not sure how
to insert the modified data back into the original string at the correct
location.
Any help would be appreciated.
Thanks,
--
_______ - ----------------------------------------------/-//- -
|: | (_) o jesse @ jesseward . com
|. |____ __
| | :|(__)
|_______| .| - -------------------------- -- - - -
|_____| 3 2308
"Jesse" <je*****@SPAMje sseward.com> wrote in message
news:10******** ******@nws01ykf .rim.net... I have a string with the following information.
$myString = "This is my example string please. Please visit http://www.mylink.com . More example text goes here. another link http://www.link2.com . more text.. blah..";
What I'm wanting is a function to return the following string :
$myString = This is my example string please. Please visit <a href'http://www.mylink.com' >link</a> . More example text goes here. another link <a href='http://www.link2.com'> link</a> . more text..
blah.."; Each string may contain 0 or more http:// instances. The function would only parse on an http:// match.
I know this could be done with regular expressions, but I'm not sure how to insert the modified data back into the original string at the correct location.
Any help would be appreciated.
Thanks,
-- _______ - ----------------------------------------------/-//- - |: | (_) o jesse @ jesseward . com |. |____ __ | | :|(__) |_______| .| - -------------------------- -- - - - |_____|
$myString = "This is my example string please. Please visit http://www.mylink.com . More example text goes here. another link http://www.link2.com . more text.. blah..";
$myString = preg_replace("| (http://\S*)|i","<a
href=\"$1\">lin k</a>",$myString) ;
kingofkolt wrote: $myString = "This is my example string please. Please visit http://www.mylink.com . More example text goes here. another link http://www.link2.com . more text.. blah.."; $myString = preg_replace("| (http://\S*)|i","<a href=\"$1\">lin k</a>",$myString) ;
thanks! works great.
--
_______ - ----------------------------------------------/-//- -
|: | (_) o jesse @ jesseward . com
|. |____ __
| | :|(__) www . jesseward . com
|_______| .| - -------------------------- -- - - -
|_____|
While the city slept, kingofkolt (je**********@c omcast.net) feverishly
typed... "Jesse" <je*****@SPAMje sseward.com> wrote in message news:10******** ******@nws01ykf .rim.net... I have a string with the following information.
$myString = "This is my example string please. Please visit http://www.mylink.com . More example text goes here. another link http://www.link2.com . more text.. blah..";
What I'm wanting is a function to return the following string :
$myString = This is my example string please. Please visit <a href'http://www.mylink.com' >link</a> . More example text goes here. another link <a href='http://www.link2.com'> link</a> . more text.. blah..";
Each string may contain 0 or more http:// instances. The function would only parse on an http:// match.
I know this could be done with regular expressions, but I'm not sure how to insert the modified data back into the original string at the correct location. $myString = "This is my example string please. Please visit http://www.mylink.com . More example text goes here. another link http://www.link2.com . more text.. blah.."; $myString = preg_replace("| (http://\S*)|i","<a href=\"$1\">lin k</a>",$myString) ;
Works ok, unless the text is in 'normal' written language - where the full
stop (or period) would appear directly after the link (eg. "Please visit http://www.mylink.com. More example text..."), in which case the closing
full stop will be a part of the link, and therefore result in a broken link.
Too late at night for me to start thinking how to overcome that, though! ;-)
Cheers,
Nige
--
Nigel Moss http://www.nigenet.org.uk
Mail address not valid. ni***@DOG.nigen et.org.uk, take the DOG. out!
In the land of the blind, the one-eyed man is very, very busy! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ram Laxman |
last post by:
Hi all,
I have a text file which have data in CSV format.
"empno","phonenumber","wardnumber"
12345,2234353,1000202
12326,2243653,1000098
Iam a beginner of C/C++ programming.
I don't know how to tokenize the comma separated values.I used strtok
function reading line by line using fgets.but it gives some weird
behavior.It doesnot stripout the "" fully.Could any body have sample
code for the same so that it will be helfful for my...
|
by: |
last post by:
Hi,
I need to read a big CSV file, where different fields should be converted to
different types,
such as int, double, datetime, SqlMoney, etc.
I have an array, which describes the fields and their types. I would like
to somehow store a reference to parsing operations in this array
(such as Int32.Parse, Double.Parse, SqlMoney.Parse, etc),
so I can invoke the appropriate one without writing a long switch.
|
by: Jon Davis |
last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST"
The problem:
// this fails on PST
DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST");
Help?
Jon
|
by: Jon Davis |
last post by:
I have put my users through so much crap with this bug it is an absolute
shame.
I have a product that reads/writes RSS 2.0 documents, among other things.
The RSS 2.0 spec mandates an en-US style of date formatting (RFC 822). I
have been using a variation of RFC 1123 (just change the time zone to an
offset, i.e. "-0800"). It seems to be writing okay, but it's failing to
parse.
I've tried changing the regional & language settings in my...
|
by: tshad |
last post by:
Is there any difference between convert.ToDateTime and
System.DateTime.Parse?
I am using them both and they seem the same.
Is one better to use than another?
Thanks,
Tom
| |
by: mike |
last post by:
Hello, I am trying to write some code to parse a sentence and hyperlink
just the words in it. I used Aaron's code from an earlier question as
a start.
So far, all the code does below is hyperlink everything separated by a
space, which means stuff like "work." "happy." "Well;" "not." from the
sentence become hyperlinks (whereas im interested in just the words
themselves becoming hyperlinks and the punctuation staying
nonhyperlinks). ...
|
by: gs |
last post by:
let say I have to deal with various date format and I am give format string
from one of the following
dd/mm/yyyy
mm/dd/yyyy
dd/mmm/yyyy
mmm/dd/yyyy
dd/mm/yy
mm/dd/yy
dd/mmm/yy
mmm/dd/yy
|
by: AdrianH |
last post by:
Assumptions
I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming.
FYI
Although I have called this article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
|
by: AdrianH |
last post by:
Assumptions
I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming.
FYI
Although I have called this article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |