473,395 Members | 1,539 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,395 software developers and data experts.

How to do search and replace in an html file?

I've written a script that extracts part of a remote web page for me to
put into a mac dashboard widget. What I need to do is replace each:

<a class='pollBoxA' href='http://www.foobar.com'> text goes here </a>

with

<span onclick=”widget.openURL(‘http://www.foobar.com/’);”> text goes
here</span>.

Here's an example of the output:

<!-- ***START*** [New Forum Posts] ***START*** -->

.....
<tr><!-- Row Four [body content]-->
<td background="interface/box_L4.gif" width=6><img
src="interface/spacer.gif" width=1 height=1></td>
<td background="interface/box_C4.gif" width="100%"><table border=0
cellspacing=0 cellpadding=0 width='100%'><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186890#186890'>Sometimes,
cutting into the present releases the
future</a></td></tr><tr><td>&nbsp;</td><td class='pollBoxData'>by
<b>Loopy C</b></td></tr><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186889#186889'>Why
Arturia should do a Buchla System 200
V...</a></td></tr><tr><td>&nbsp;</td><td class='pollBoxData'>by
<b>donaldm</b></td></tr><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186888#186888'>machine
freezes whhen running Logic</a></td></tr><tr><td>&nbsp;</td><td
class='pollBoxData'>by <b>kanker</b></td></tr><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186887#186887'>Luxonix
Ravity AU Available!</a></td></tr><tr><td>&nbsp;</td><td
class='pollBoxData'>by <b>mr.jones</b></td></tr><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186886#186886'>Best
Recording Technique for Flute</a></td></tr><tr><td>&nbsp;</td><td
class='pollBoxData'>by <b>kanker</b></td></tr><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186885#186885'>EMS
1000+ posts - Congratulate me and boost your post
count!</a></td></tr><tr><td>&nbsp;</td><td class='pollBoxData'>by
<b>?bob</b></td></tr><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186884#186884'>Sample
Manager refuses to start up</a></td></tr><tr><td>&nbsp;</td><td
class='pollBoxData'>by <b>jamieh</b></td></tr><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186878#186878'>Firewire
interface - converter/pre quality?</a></td></tr><tr><td>&nbsp;</td><td
class='pollBoxData'>by <b>captain54</b></td></tr><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186876#186876'>Reason
and wave samples?</a></td></tr><tr><td>&nbsp;</td><td
class='pollBoxData'>by <b>Wil1870</b></td></tr><tr><td width=15><img
src='interface/arrowOrange_right.gif' alt='' width=9 height=8
border=0></td><td><a class='pollBoxA'
href='http://www.osxaudio.com/forums/viewtopic.php?p=186871#186871'>Best
USB Hub</a></td></tr><tr><td>&nbsp;</td><td class='pollBoxData'>by
<b>lance</b></td></tr></table>
.......
<!-- ***END*** [New Forum Posts] ***END*** -->
How on earth can I do this?

Thanks,

Kev

Jul 17 '05 #1
3 1900
As you are assuming that Javascript is enabled, why not just append a
script section to the HTML code and attach an onclick listener to the
document?

Jul 17 '05 #2
Kevin Morgan (ke***@nospammistever.co.uk) decided we needed to hear...
I've written a script that extracts part of a remote web page for me to
put into a mac dashboard widget. What I need to do is replace each:

<a class='pollBoxA' href='http://www.foobar.com'> text goes here </a>

with

<span onclick=⤝widget.openURL(=3Fhttp://www.foobar.com/=3F);⤝> text goes
here</span>.
Your best bet is probably using a regex. Check out some of the PHP
functions here http://www.php.net/manual/en/ref.pcre.php
You'll find some good examples and tutorial links here
http://www.regexplib.com/Default.aspx

<snip example output>

How on earth can I do this?

Thanks,

Kev



--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #3
here's a regex i threw together using regex coach - really nice little
tool. only problem with it is that you have to escape some of the
characters when you put it into php.

<a\sclass='pollBoxA'\shref='(http://.*?')>(.*?)</a>

for example, you'll need to escape the "<" I think, but not the ">".
also you'll probably need to escape the apostraphes. but this is a
good starting point for developing regex's.

Jul 17 '05 #4

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

Similar topics

1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
5
by: Abby Lee | last post by:
My code does what I want (works unless there is a lot of volume...works for this month cause not a lot of items marked paid yet...) but the page times out for last month because there is just so...
1
by: Luke Dalessandro | last post by:
I have an application where there is a primary XML data file. I'll use the following as an example: <data> <item id="a"> <name>A</name> <price>$10</price> </item> <item id="b">...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
2
by: Dennis | last post by:
I am trying to implement a "Find and Replace" dialog that allows using wildcards in the find string, much like the Find and Replace Dialogs in Ms Word, etc. Are there any references or examples on...
5
by: int main(void) | last post by:
Hi all, Following is my attempt to write a string search and replace function. #include <stdio.h> #include <stdlib.h> #include <string.h>...
5
by: foolproofplan | last post by:
Hey everyone. I am running into a problem with unique ids that need to be compared in two xml files. The actual object name is represented with its unique id later in the xml file, so i need to do...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
5
by: silmana | last post by:
Hi i have this script that i want to use as php or html but i cant find the problem, could anyone solve the problem, i dont know why i cannot use it in php or html file // OBS! Ngra saker mste...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
jinu1996
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...
0
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...
0
tracyyun
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...

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.