Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Personalization
Expertise: Beginner
Apr 30, 1997

IMG tag and relative/evaluated location

Question:
We have a structure already defined that is now being modified, containing more than 400 pages that include IMG tags. The entire "mess" is being moved to another server/structure such that the relative references in the IMG tags will no longer be valid.

Is there any way other than (a) editing 400+ individual HTML docs, or (b) writing a script to perform the changes, that allows for the "../../" relative references in the IMG tags to be evaluated with some type of variable a la UNIX scripts? Or is this beyond the scope of basic HTML?

For example, IMG SRC="../../abc/mygif.gif" — is there any way to have "../../abc/" replaced with a variable entity/expression that can be evaluated in its place, as in: IMG SRC=some_token "mygif.gif"?

Answer:
You will need to either run a script or use a local editor, such as HomeSite, to edit the path names. A simple search and replace script would be something like this:

#! /bin/csh

# Call this file snr.sh
# Replace FILE with * for all files, or a partial file name
# Replace OLDPATH with the old path name and NEWPATH with
# the new path name.
# Don't forget to backslash any slashes, so if the OLDPATH is
# ../../ you will need to type ..\/..\/

foreach f (FILE)
foreach g ($f/*.html)

	cat $g | sed -e 's/OLDPATH/NEWPATH/g' > tmp
	mv -f tmp $g
end
end
Place it in the root directory, and make it executable by typing:
%  chmod +x snr.sh
and run it by typing:
%  snr.sh
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date