By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

How to do search and replace in an html file?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.