473,399 Members | 2,159 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,399 software developers and data experts.

Using ASP to replace content but not tag content in HTML pages

Hi,

Using ASP I'd like to modify a string that contains HTML.

I need to modify the content (the bit that the users see) but not the stuff
in the tags.

For example, if I had the following string

<a href=www.replacetext.com>replacetext.com</a>

and wanted to replace "replacetext.com" with "newtext.com" I'd want the
output to be

<a href=www.replacetext.com>newtext.com</a>

Could anyone help me with this?

Thanks,

Ben.
Jul 22 '05 #1
13 1667
"Sir Ben" wrote in message
news:LU*******************@newsfe1-gui.ntli.net...
: Using ASP I'd like to modify a string that contains HTML.
:
: I need to modify the content (the bit that the users see) but not the
stuff
: in the tags.
:
: For example, if I had the following string
:
: <a href=www.replacetext.com>replacetext.com</a>
:
: and wanted to replace "replacetext.com" with "newtext.com" I'd want the
: output to be
:
: <a href=www.replacetext.com>newtext.com</a>
:
: Could anyone help me with this?

Ya', I could do that but looking at your email addy, does this mean I'm
going to get some pr0n spam with disguised links?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #2
Roland,

Thanks for replying.

No, you won't be getting any porn spam links as that would be very rude to
someone who's helping me and you've given a oid email address anyway.

Could you please post a solution on this newsgroup?

Thanks,

Sir Ben.

"Roland Hall" <nobody@nowhere> wrote in message
news:em**************@TK2MSFTNGP10.phx.gbl...
"Sir Ben" wrote in message
news:LU*******************@newsfe1-gui.ntli.net...
: Using ASP I'd like to modify a string that contains HTML.
:
: I need to modify the content (the bit that the users see) but not the
stuff
: in the tags.
:
: For example, if I had the following string
:
: <a href=www.replacetext.com>replacetext.com</a>
:
: and wanted to replace "replacetext.com" with "newtext.com" I'd want the
: output to be
:
: <a href=www.replacetext.com>newtext.com</a>
:
: Could anyone help me with this?

Ya', I could do that but looking at your email addy, does this mean I'm
going to get some pr0n spam with disguised links?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp

Jul 22 '05 #3
Strangely enough I was thinking the same thing......

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Roland Hall" <nobody@nowhere> wrote in message news:em**************@TK2MSFTNGP10.phx.gbl...
"Sir Ben" wrote in message
news:LU*******************@newsfe1-gui.ntli.net...
: Using ASP I'd like to modify a string that contains HTML.
:
: I need to modify the content (the bit that the users see) but not the
stuff
: in the tags.
:
: For example, if I had the following string
:
: <a href=www.replacetext.com>replacetext.com</a>
:
: and wanted to replace "replacetext.com" with "newtext.com" I'd want the
: output to be
:
: <a href=www.replacetext.com>newtext.com</a>
:
: Could anyone help me with this?

Ya', I could do that but looking at your email addy, does this mean I'm
going to get some pr0n spam with disguised links?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp



Jul 22 '05 #4
I feel this is most unfair. Especially as there's no way of me to SPAM you
anyway.

Is there nothing I can do to convince you to help me? I've even changed my
name now!
"Steven Burn" <so*******@in-time.invalid> wrote in message
news:OM**************@TK2MSFTNGP15.phx.gbl...
Strangely enough I was thinking the same thing......

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Roland Hall" <nobody@nowhere> wrote in message
news:em**************@TK2MSFTNGP10.phx.gbl...
"Sir Ben" wrote in message
news:LU*******************@newsfe1-gui.ntli.net...
: Using ASP I'd like to modify a string that contains HTML.
:
: I need to modify the content (the bit that the users see) but not the
stuff
: in the tags.
:
: For example, if I had the following string
:
: <a href=www.replacetext.com>replacetext.com</a>
:
: and wanted to replace "replacetext.com" with "newtext.com" I'd want the
: output to be
:
: <a href=www.replacetext.com>newtext.com</a>
:
: Could anyone help me with this?

Ya', I could do that but looking at your email addy, does this mean I'm
going to get some pr0n spam with disguised links?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


Jul 22 '05 #5
"Sir Ben" wrote in message
news:ec*******************@newsfe1-gui.ntli.net...
: Roland,
:
: Thanks for replying.
:
: No, you won't be getting any porn spam links as that would be very rude to
: someone who's helping me and you've given a oid email address anyway.
:
: Could you please post a solution on this newsgroup?

ok, just a min... brb
Jul 22 '05 #6
Bit sloppy but, see if this helps;

sSource = "<a href=""somewebsite.com"">somewebsite.com</a>"
sReplaceWhat = "somewebsite.com"
sReplaceWith = "someotherwebsite.com"
Response.Write Replace(sSource, ">" & sReplaceWhat & "<", ">" & sReplaceWith & "<")

There's an example here;

http://mysteryfcm.plus.com/misc/srep.asp

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Lazaroo" <ju**@financialcharting.com> wrote in message news:dD*******************@newsfe1-gui.ntli.net...
I feel this is most unfair. Especially as there's no way of me to SPAM you
anyway.

Is there nothing I can do to convince you to help me? I've even changed my
name now!
"Steven Burn" <so*******@in-time.invalid> wrote in message
news:OM**************@TK2MSFTNGP15.phx.gbl...
Strangely enough I was thinking the same thing......

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Roland Hall" <nobody@nowhere> wrote in message
news:em**************@TK2MSFTNGP10.phx.gbl...
"Sir Ben" wrote in message
news:LU*******************@newsfe1-gui.ntli.net...
: Using ASP I'd like to modify a string that contains HTML.
:
: I need to modify the content (the bit that the users see) but not the
stuff
: in the tags.
:
: For example, if I had the following string
:
: <a href=www.replacetext.com>replacetext.com</a>
:
: and wanted to replace "replacetext.com" with "newtext.com" I'd want the
: output to be
:
: <a href=www.replacetext.com>newtext.com</a>
:
: Could anyone help me with this?

Ya', I could do that but looking at your email addy, does this mean I'm
going to get some pr0n spam with disguised links?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp





Jul 22 '05 #7
I should mention, my "solution" is going to look extremely pitiful compared to Roland's (usually does <g>) so you may want to wait for his ;o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Jul 22 '05 #8
Thanks for the help Steven!

I kept on searching and after 3 hours I finally got what I wanted!!!!

It was on this site:

http://coveryourasp.com/ShowFileDescr.asp

And the code for anyone else interested is below...

function htmlContentReplace(strHTML,strSearch,strReplace)
htmlContentReplace = RegExpReplace(strHTML, "(?![^<]+>)" + strSearch +
"(?![^<]+>)", strReplace)
'htmlContentReplace = RegExpReplace(strHTML, "(?![^<\[]+[>\]])" + strSearch
+ "(?![^\[<]+[>\]])", strReplace)
end function

Function RegExpReplace(strInput, strPattern, strReplace)
' Use <?> to indicate the match you wish to replace
' Create and setup several variables:
Dim regEx, Match, Matches, Position, strReturn
Position = 1
strReturn = ""

' Set up the regular expression:
Set regEx = New RegExp
regEx.Pattern = strPattern
regEx.IgnoreCase = True
regEx.Global = True

' Get all the matches for it:
Set Matches = regEx.Execute(strInput)

' Go through the Matches collection
' and build the output string:
For Each Match in Matches
strReturn=strReturn & Mid(strInput, Position,
Match.FirstIndex+1-Position)
strReturn=strReturn & Replace(strReplace, "<?>", Match.Value)
Position = Len(Match.Value) + Match.FirstIndex + 1
Next

' Add any text after the last match
strReturn = strReturn & Mid(strInput, Position, Len(strInput))
RegExpReplace = strReturn
End Function
"Steven Burn" <so*******@in-time.invalid> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I should mention, my "solution" is going to look extremely pitiful compared
to Roland's (usually does <g>) so you may want to wait for his ;o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
Jul 22 '05 #9
"Roland Hall" wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
: "Sir Ben" wrote in message
: news:ec*******************@newsfe1-gui.ntli.net...
:: Roland,
::
:: Thanks for replying.
::
:: No, you won't be getting any porn spam links as that would be very rude
to
:: someone who's helping me and you've given a oid email address anyway.
::
:: Could you please post a solution on this newsgroup?
:
: ok, just a min... brb

Only gone 10 minutes. Everything's bigger in Texas! (O;=-

I see you found something Sir Ben, a.k.a. Lazaroo...

Here is what I came up with:

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True

function disguise(str, strR)
dim re, col, strLeft, strRight
set re = new RegExp
with re
.Pattern = "<[^>]*>"
.Global = true
.IgnoreCase = true
end with
set col = re.Execute(str)
disguise = col(0) & strR & col(1)
set col = nothing
set re = nothing
end function

dim original, replacement, strNew
original = "<a href=www.replacetext.com>replacetext.com</a>"
replacement = "newtext.com"
strNew = disguise(original, replacement)

Response.Write "Original: " & Server.HTMLEncode(original) & "<br />" &
vbCrLf
Response.Write "Replacement: " & replacement & "<br />" & vbCrLf
Response.Write "New String: " & Server.HTMLEncode(strNew)
%>

I encoded the strings so they would display properly in the example when you
run it. They're not needed otherwise.
You can see it working here: http://kiddanger.com/lab/htmlx2.asp

HTH... (no spamming... you promised)

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #10
"Steven Burn" wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I should mention, my "solution" is going to look extremely pitiful compared
to Roland's (usually does <g>) so you may want to wait for his ;o)

Oh puhleease. I often have to pull out my reference material to read your
code. I've even sent some of it out to be analyzed at HowdTheyDoThat.com
and the response is always the same:

"We're as baffled as you are. This guy's IQ must be off the chart!"

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #11
I just noticed... this:

: dim re, col, strLeft, strRight

should be:

dim re, col

....only. Those two variables are no longer being used.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #12
ROFLMFAO!

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Roland Hall" <nobody@nowhere> wrote in message news:OX**************@TK2MSFTNGP14.phx.gbl...
"Steven Burn" wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I should mention, my "solution" is going to look extremely pitiful compared
to Roland's (usually does <g>) so you may want to wait for his ;o)

Oh puhleease. I often have to pull out my reference material to read your
code. I've even sent some of it out to be analyzed at HowdTheyDoThat.com
and the response is always the same:

"We're as baffled as you are. This guy's IQ must be off the chart!"

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp



Jul 22 '05 #13
Your welcome....... glad to see you found something to suit your needs ;o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Lazaroo" <ju**@financialcharting.com> wrote in message news:pG******************@newsfe1-gui.ntli.net...
Thanks for the help Steven!

I kept on searching and after 3 hours I finally got what I wanted!!!!

It was on this site:

http://coveryourasp.com/ShowFileDescr.asp

And the code for anyone else interested is below...

function htmlContentReplace(strHTML,strSearch,strReplace)
htmlContentReplace = RegExpReplace(strHTML, "(?![^<]+>)" + strSearch +
"(?![^<]+>)", strReplace)
'htmlContentReplace = RegExpReplace(strHTML, "(?![^<\[]+[>\]])" + strSearch
+ "(?![^\[<]+[>\]])", strReplace)
end function

Function RegExpReplace(strInput, strPattern, strReplace)
' Use <?> to indicate the match you wish to replace
' Create and setup several variables:
Dim regEx, Match, Matches, Position, strReturn
Position = 1
strReturn = ""

' Set up the regular expression:
Set regEx = New RegExp
regEx.Pattern = strPattern
regEx.IgnoreCase = True
regEx.Global = True

' Get all the matches for it:
Set Matches = regEx.Execute(strInput)

' Go through the Matches collection
' and build the output string:
For Each Match in Matches
strReturn=strReturn & Mid(strInput, Position,
Match.FirstIndex+1-Position)
strReturn=strReturn & Replace(strReplace, "<?>", Match.Value)
Position = Len(Match.Value) + Match.FirstIndex + 1
Next

' Add any text after the last match
strReturn = strReturn & Mid(strInput, Position, Len(strInput))
RegExpReplace = strReturn
End Function


"Steven Burn" <so*******@in-time.invalid> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I should mention, my "solution" is going to look extremely pitiful compared
to Roland's (usually does <g>) so you may want to wait for his ;o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!



Jul 22 '05 #14

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

Similar topics

4
by: Jane Doe | last post by:
Hi, I need to search and replace patterns in web pages, but I can't find a way even after reading the ad hoc chapter in New Rider's "Inside JavaScript". Here's what I want to do: function...
0
by: Phil Grimpo | last post by:
I have an application where users create pages using a WYSIWYG editor and the content is stored in the database. For "custom tags" the stored html will have something like {%Contact_Form%}. So...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
0
by: AlexW | last post by:
This stuff is new to me except for frames. I can't see how Master pages can provide a sizable splitter that frames can do and very easly fill each frame with an untouched aspx form. It's...
133
by: Alan Silver | last post by:
Hello, Just wondered what range of browsers, versions and OSs people are using to test pages. Also, since I don't have access to a Mac, will I have problems not being able to test on any Mac...
2
by: bj | last post by:
Hi, Yes, this is yet another "switching from tables to divs for layout purposes" post. I have been searching for the past few hours to find what I'm looking for as I hate posting unnecessarily....
3
by: Paul | last post by:
I found a great site for CSS tempaltes, http://blog.html.it/layoutgala/ . I downloaded them, and played around with them. Then I tried to use the template in as ASP.Net MasterPage, but everything...
3
by: apiringmvp | last post by:
All, So I am creating a function that gets a short blurb of html from a blog. I would like to retain all html formating and images. The code below works well, with the exception of one issue....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.