Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing a html file and replacing values

Status
Not open for further replies.

kaancho12

Technical User
Feb 22, 2005
191
hi,
I have this problem of parsing html file and i need some suggestions on how to go about it. i have to parse lots of html files and add some contents at specific point in those files.
for example the files might look like this:
<html>
<head></head><body>
<table>
<tr><td>TestA<A HREF="ABC16.html">ABC16</A></td></tr>
<tr><td>Test B<A HREF="ABC17.html">ABC17</A></td></tr>
<tr><td>Test C<A HREF="ABC18.html">ABC18</A></td></tr>
<tr><td>Some text in between and some other tags <b>tags</b></td></tr>
<tr><td>Test D<A HREF="qwe19.html">qwe19</A></td></tr>
<tr><td>Test E<A HREF="rst20.html">rst20</A></td></tr>
</table>
</body>
</html>
Now, I have to add a button after each of the link that starts with "ABC" and that button has to go that specific page. Say if the link name is ABC16.html I want to add a button which is like
<input TYPE="BUTTON" NAME="b1" VALUE="Click Here To Order" onClick="Locat('webaddress');return false">
I need help on how to find links that start with "ABC" and how to add a button after that link is finished. Any suggestions??? There are a lot of files otherwise i would do this manually :))
thank you
ko12
 
i assume that this is a runonce activity?

dreamweaver's search and replace function will do this for you (across multiple files).

if the new button insert is dynamic (ie values change depending on the link value) then you're looking at preg_replace or ereg_replace (i.e. regular expressions).
 
hi,
thanks for your suggestion. i will look more at preg_replace or ereg_replace.
also i just realised the link name does not have "ABC" in front of the number. For example, the links are placed like this:
<tr><td>TestA<A HREF="ABC16.html">16</A></td></tr>
<tr><td>Test B<A HREF="ABC17.html">17</A></td></tr>
<tr><td>Test C<A HREF="ABC18.html">18</A></td></tr>
I hope this wont be affected because i will have to compare the link name and the immediate name of the link after it.
thanks
ko12
 
one thought: are the links generated dynamically or are they hard coded in the html?
 
the links are hardcoded in the html and i just want to add a button after the link which will take them to another page not the "html" page where there will be a different information.
for example:
Before Parsing:
<tr><td>
TestA<A HREF="ABC16.html">16</A>
</td></tr>
After Parsing:
<tr><td>TestA<A HREF="ABC16.html">16</A>
<br>
<input TYPE="BUTTON" NAME="b1" VALUE="Click Here To Order" onClick="Locat(' false">
</td></tr>

Is there an example of preg_replace that you can give me where I can match up anything that finds pattern and the value inside <a> tags such as this
<a href="ABC$$$.html">ABC$$$</a>
thank you for your help
ko12
 
hi,
ok, after reading for a bit here's the code i came up with to match the link inside "<a href" but it doesnt seem to work --could u suggest how i may improve this:

preg_match("/(^HREF[^>]*>).*?(<\/A>)/","<A HREF=\"/10to99/pdf/ABC20.pdf\">ABC</a>", $matches);
echo "matches: " . $matches[0] . "<br>";

thanks
ko12
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top