Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find and replace code in HTML files (no jQuery)

Posted on 2013-01-21
6
Medium Priority
?
311 Views
Last Modified: 2013-10-09
I have 3000+ html files in a folder. Is it possible to use any scripting to find inside all html files, any image tag that has src="XXX_logo.png" and add text ending with " logo" to the alt attribute which already contains a value?

I can't use jQuery.

EG:
BEFORE:
<div class="copyright">
<div class="floatleft"><img src="support_files/organisation_logo.png" alt="The organisation" width="104" height="48" class="floatleft"/></div>
<div class="footer-statements"><div class="floatright"><img src="support_files/partner_logo.png" alt="Organisation partner name" width="273" height="48" /></div>
<div class="copyright-lines"><!-- metadata:content-rights--></div>
</div>

Open in new window



AFTER (desired result):
<div class="copyright">
<div class="floatleft"><img src="support_files/organisation_logo.png" alt="The organisation logo" width="104" height="48" class="floatleft"/></div>
<div class="footer-statements"><div class="floatright"><img src="support_files/partner_logo.png" alt="Organisation partner name logo" width="273" height="48" /></div>
<div class="copyright-lines"><!-- metadata:content-rights--></div>
</div>

Open in new window

0
Comment
Question by:jeremyll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38804294
If you use jquery, you would still have to update 3000 pages.  Your dreamweaver can do the find and replace.  You can also do a find and replace in windows or mac automator.   Do you actually have 3000 hard coded html pages or 3000 pages that are really just a handful generated by your database?
0
 

Author Comment

by:jeremyll
ID: 38804366
There's 3000 hard coded HTML pages.

I don't think you can do a find and replace with dreamweaver.

Each HTML page has three images, but I only want to append " logo" to the end of the text in the alt attribute for just two images.
0
 
LVL 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 38805772
You can do a find and replace with dreamweaver.  Anything from very simple to using reg ex.  You can find and replace by selected text, entire document open, all open files, all files in a "site" or all files in a folder.  As long as you have a pattern you can do it.   I have never tried it with 3000 pages with dreamweaver.  

If you have a javascript or include file in one spot and want to use jquery you would use

$(document).ready(function() {
$('.copyright .floatleft img').attr('alt', 'The organisation logo');
$('.footer-statements img').attr('alt', 'Organisation partner name logo');
 });
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 38806362
You can write a application that

1.Gets all the files in the folders
2. Open each file, use regex to search for the string and then perform the task as required
3. Save back the file :)


This utility can me easily written in C# or Vb.Net and will work like a charm :)

Hope this will give you some idea to solve ur problem
0
 

Author Comment

by:jeremyll
ID: 38807794
@padas - 'The organisation' is meant to be the variable, so I'm not replacing text with 'The organisation logo'. It should be '{variable name} logo'

@AmanBhullar - Unfortunately, don't know c# or vb.net well enough to write the script.

Someone has come up with perl script which I don't know either. :-(

perl -pi -e 'if(/<img src=\".*_logo.png/){s/(.*alt=\"[^\"]*)\"(.*)/$1 logo\"$2/g}' *.html

Looks logical though..
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38807833
I'm sorry, my eyes read one thing and brain processed another.   Using jquery could do the same thing searching for any image tag that has src="XXX_logo.png.  For me personally, it is easier then regex which is what the perl script is doing.  You can use the same regex commands in dreamweaver by the way.    Also if the variable is the text, jquery can simply append the word logo instad of replacing as I did.  

If this is a one time permanent thing you will not need to do again, I would go with the find and replace and be done with it.  But the js option is non destructive.  With 3000 pages, something is bound to be different then what you expected.

If you can get that perl script to work once, I would use that.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Starting up a Project

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question