Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- inserting text into HTML
May 18, 2007, 1:26 pm
rate this thread
I have a big list of HTML files, which need to be updated with a
I need to add the above line in each of the html files, before the
text "<\head>". All the HTML files have this text and I think some
kind of search on this string and either replacing "</head>" with the
text above and appending "<\head> to it, might be one way to do it or
just find the <\head> part and insert the text before that.
On similar lines, the text below goes towards the end. The problem is
similar to the above one and I think all that needs to be done, is
read the text below from a file, do a similar search for some text
below which this insert part should go and put it there.
var mailBody = 'Your Technical Support Team hopes this topic will
be helpful: ' + location.href;
var mailDisplay = 'Click here to email this topic.';
+ '?subject=' + escape(mailSubject)
+ '&body=' + escape(mailBody)
+ '">' + mailDisplay + '</a>'
Any ideas would be helpful. I do not know much about perl and hence
the more the better.
Thanks a lot
Re: inserting text into HTML
Oh, you mean </head>. Are you sure? Well, then you could write a Perl
few-liner to do the job, or ask someone to write it for you. You would still
need to learn how to run a Perl program _on the server_. The program could
be something like the following (untested):
$filename = $_;
|| die "Can't open file \"$filename\":\n $!";
$stuff = <FILE>;
|| die "Can't open file \"$filename\" for writing:\n $!";
print FILE $stuff;
Of course, this isn't real about authoring in HTML. The c.i.w.a.tools group
would have been more suitable. And of course you might find an editor with a
built-in multi-file string replace feature that could be used for the job.
Well, of course it would be similar, with similar solutions, though
detecting the end is non-trivial. But...
This sounds like a _very_ clueless method of giving some users some poor way
of contacting you, instead of simply telling all users your email address.
So if you do something _so_ stupid, at least do it via some server-side
include feature, so that when you come to your senses, you won't have to fix
a zillion files again but can simply fix the included file.
Jukka K. Korpela ("Yucca")
May 18, 2007, 9:10 pm
Re: inserting text into HTML
Slain wrote :
First language is deprecated; type is the normal replacement and it is
both backward and forward-compatible.
Just use an advanced text editor to do that. It's simple to do.
Free software (libre/open-source) text editors:
You're overreaching here in my opinion. And your code has problems.
First, you must escape the ampersand with &
Second, you are adding a closing </p> tag when there is not a start <p>.
Third, you'll need to escape the closing tags inside the document.write
Common HTML Validation Problems
Writing HTML in a SCRIPT element
HTML 4, Section 18.2.4 Dynamic modification of documents
HTML 4, Appendix B.3.2 Specifying non-HTML data, Element Content
"When script or style data is the content of an element (SCRIPT and
STYLE), the data begins immediately after the element start tag and ends
at the first ETAGO ("</") delimiter followed by a name start character
([a-zA-Z]); note that this may not be the element's end tag. Authors
should therefore escape "</" within the content."
As mentioned already, language attribute is deprecated.
Don't use HTML comments as they are unneeded, unnecessary and
Don't Use HTML Comments In Script Blocks
Validate your markup code! Preferably with/for a strict DTD.
Using Web Standards in your Web Pages (Updated Apr. 2007)