WebDev Masters

Web Development & Webmaster Resources

Browsing Posts tagged Using

In this article we will discuss how to change the contents of an HTML file by running a Perl script on it.

The file we are going to process is called file1.htm:

Note: To ensure that the code is displayed correctly, in the example code shown in this article, square brackets ‘[..]‘ are used in HTML tags instead of angle brackets ”.

[html]
[head][title]Sample HTML File[/title]
[link rel="stylesheet" type="text/css" rel="nofollow" onclick="javascript:pageTracker._trackPageview('/outgoing/article_exit_link');" href="style.css"]
[/head]
[body]
[h1]Introduction[/h1]
[p]Welcome to the world of Perl and regular expressions[/p]
[h2]Programming Languages[/h2]
[table border="1" width="400"]
[tr][th colspan="2"]Programming Languages[/th][/tr]
[tr][td]Language[/td][td]Typical use[/td][/tr]
[tr][td]JavaScript[/td][td]Client-side scripts[/td][/tr]
[tr][td]Perl[/td][td]Processing HTML files[/td][/tr]
[tr][td]PHP[/td][td]Server-side scripts[/td][/tr]
[/table]
[h1]Summary[/h1]
[p]JavaScript, Perl, and PHP are all interpreted programming languages.[/p]
[/body]
[/html]

Imagine that we need to change both occurrences of [h1]heading[/h1] to [h1 class="big"]heading[/h1]. Not a big change and something that could be easily done manually or by doing a simple search and replace. But we’re just getting started here.

To do this, we could use the following Perl script (script1.pl):

1 open (IN, “file1.htm”);
2 open (OUT, “>new_file1.htm”);
3 while ($line = [IN]) {
4 $line =~ s/[h1]/[h1 class="big"]/;
5 (print OUT $line);
6 }
7 close (IN);
8 close (OUT);

Note: You don’t need to enter the line numbers. I’ve included them simply so that I can reference individual lines in the script.

Let’s look at each line of the script.

Line 1
In this line file1.htm is opened so that it can be processed by the script. In order to process the file, Perl uses something called a filehandle, which provides a kind of link between the script and the operating system, containing information about the file that is being processed. I’ve called this “opening” filehandle ‘IN’, but I could have used anything within reason. Filehandles are normally in capitals.

Line 2
This line creates a new file called ‘new_file1.htm’, which is written to by using another filehandle, OUT. The ‘>’ just before the filename indicates that the file will be written to.

Line 3
This line sets up a loop in which each line in file1.htm will be examined individually.

Line 4
This is the regular expression. It searches for one occurrence of [h1] on each line of file1.htm and, if it finds it, changes it to [h1 class="big"].

Looking at Line 4 in more detail:

$line – This is a variable that contains a line of text. It gets modified if the substitution is successful.

=~ is called the comparison operator.

s is the substitution operator.

[h1] is what needs to be substituted (replaced).

[h1 class="big"] is what [h1] has to be changed to.

Line 5
This line takes the contents of the $line variable and, via the OUT file handle, writes the line to new_file1.htm.

Line 6
This line closes the ‘while’ loop. The loop is repeated until all the lines in file1.htm have been examined.

Lines 7 and 8
These two lines close the two file handles that have been used in the script. If you missed off these two lines the script would still work, but it’s good programming practice to close file handles, thus freeing up the file handle names so they can be used, for example, by another file.

Running the Script

As the purpose of this article is to explain how to use regular expressions to process HTML files, and not necessarily how to use Perl, I don’t want to spend too long describing how to run Perl scripts. Suffice to say that you can run them in various ways, for example, from within a text editor such as TextPad, by double-clicking the perl script (script1.pl), or by running the script from an MS-DOS window.

(The location of the Perl interpreter will need to be in your PATH statement so that you can run Perl scripts from any location on your computer and not just from within the directory where the interpreter (perl.exe) itself is installed.)

So, to run our script we could open an MS-DOS window and navigate to the location where the script and the HTML file are located. To keep life simple I’ve assumed that these two files are in the same folder (or directory). The command to run the script is:

C:>perl script1.pl

If the script does work (and hopefully it will), a new file (new_file1.htm) is created in the same folder as file1.htm. If you open the file you’ll see the the two lines that contained [h1] tags have been modified so that they now read [h1 class="big"].

In Part 3 we’ll look at how to handle multiple files.

John is a web developer working for My Health Questions Matter, a company dedicated to helping patients to get the most out of their interaction with health care professionals such as doctors, midwives, and consultants by generating a set of health questions a patient can ask at an appointment.

Technology is constantly evolving and advancing and nothing shows this more than the (short) history of the web.  Just a few years ago, the internet was full of websites with blinking, animated icons and background midi music and lots of people thought it was really great.  Advance a few years forward and, although you still see those things from time to time, the web now contains much more sophisticated elements like video clips, rss feeds, detailed flash animations, and more.   

As the “ideas” about what a website is and what it should, or could, do for a company have also evolved, designers have strived to streamline the process of developing websites and to make them more efficient and predictable.  Because different browsers interpret code differently, it hasn’t always been easy to make more complex websites look the same (or even good in some cases) across browsers and systems. What used to work in the early days of the web was no longer working the way web designers wanted or needed it to.

Cascading Style Sheets to the Rescue
Cascading Style Sheets, also known as CSS, were introduced to improve the capabilities of web presentation.  Prior to CSS, almost all of the html attributes that made up the “look and feel” of a web page were contained within the html directly. This made web page code heavy and often quite clunky.  By using Cascading Style Sheets, designers could separate the design elements from the content of a web page and thereby make the pages more efficient, more streamlined, and easier to maintain.

Not all designers jumped on the CSS bandwagon, and even today, many designers still prefer to layout their web pages using html table-based design, the way just about everyone used to do it. Using CSS to layout a webpage is quite different from the “old fashioned” table layout.   However, the advantages to using a CSS layout for a web page heavily outweigh any argument given for using html tables.  

Although I wouldn’t expect clients to know the intricate details of Cascading Style Sheets (and let’s face it, most clients don’t really want to know much if anything about it!), I do think that clients should be aware of the advantages of using CSS layouts and how they can enhance their websites both now and in the future.

Advantages to Using CSS for Web Layout

Web pages will load faster
No one likes waiting for web pages to load and if a page takes too long to load, many users will often simply leave.  Generally speaking, CSS based page layouts require much less html coding than table-based layouts.  This usually results in the pages loading more quickly.  Moreover, an externally linked CSS file, once loaded the first time, does not have to be reloaded and re-read on every page.  When using CSS for layout, browsers can cache (keep in memory) all the formatting and stylizing for your pages instead of having to read and interpret each style tag on every page. This can also result in much faster page loading times.

Visual consistency across pages
One of the strengths of using Cascading Style Sheets in a website layout is that design elements can be defined in a single place (the css file) and will automatically be applied to those elements on the website.  No longer does each individual page have to be updated to reflect the new style.  This makes for much greater consistency throughout the site.  With CSS, you do not have to re-code every element on every page (and check and double check that you didn’t miss some pages!), styling updates are automatic and site-wide.

Accessibility and usability
CSS allows for more interactive style elements, including font size and line heights, which can make web pages more usable for people with disabilities.  Web pages that use CSS layouts are also often more compatible with more browsers.  What’s more, designers can create specific css files specifically for printing, or mobile devices, as well as the standard computer screen, thereby making websites truly multimedia applications.

CSS is better for SEO
Since pages load faster with CSS Layouts, search engines can more easily crawl through the site.  Also, since there is often less coding on the pages and because CSS separates the design elements from the content, it is easier for search engines to determine what a page is about and to index it appropriately.  Finally, search engine spiders rely heavily on structural organization (heading (h1, h2, h3, etc) tags) and CSS allows designers to design those elements as needed and to place them within the page layout in a way that is most beneficial for search engine optimization.

Future redesigns will be more efficient (read, less expensive!)
Since CSS layouts separate design elements from content, once a site has been designed using Cascading Style Sheets, making changes to the design is often easier because fewer files need to be updated (often only the css files rather than every page on the website!)  This makes for faster and less expensive design changes in the future.  Set your site up using CSS now and you can have easier, more efficient and quicker updates in the future.

Caryl A. Clippinger is a web designer & developer and a founder of Charlotte’s Web Studios, L.L.C., a Virginia web design company. For more information about Charlotte’s Web Studios and additional web design tips and resources, please visit http://www.CharlottesWebStudios.com.

Alarm is something which we have seen that can be set in wall clocks, but how about an alarm in your computer or in your website, or in a web based application that can alarm you when the set time is reached. Don’t think of a big wall clock, it’s a cute small digital clock that can be displayed anywhere in your web page without any difficult software installation.

HIOX Alarm Watch is a very useful script to intimate a user about the set alarm time, the format of the clock would be HH:MM:SS Format, it’s a digital clock that gets displayed, this can be used in any web based application to intimate an alarm on the specified time, it works great in internet explorer, but in Firefox you would require some add-on’s. This clock can also be used as a wake up alarm too.

HIOX Alarm Watch script that can be embedded into any web page. Hiox Alarm watch script can be copied to any file you want. It is used to set an alarm. Hiox Alarm watch script displays a clock and a message which says alarm OFF. Alarm time can be set using the drop down menu once set the message will change to alarm ON.

Apart from web based application web, JavaScript interpreters are embedded in a number of tools. Since JavaScript uses an interpreter, loosely-typed, and may be hosted in varying incompatible environments, a programmer has to take care to make the code execute as expected in multiple environments as possible.

Considering other tools available in the internet the HIOX Alarm Watch doesn’t require any difficult software installation. Just with the basic knowledge of programming any one could use this script with ease. This Script will be of great help to web masters, can use this script in a time based application.

This free script can be downloaded from the

URL:http://www.hscripts.com/scripts/JavaScript/alarm-clock.php , (GNU Licensed).

contact us at www.hscripts.com

YOU know what’s really amazing? You see a website that’s pretty basic, but you know it’s making its owners bucket loads of money. Then you start thinking, ‘how can I do that too?’ Well you’re going to get some tips here that’ll show you how to use a free html editor such as Kompozer to head right in that direction, and save you from getting frustrated, so read on…

Before we do though, I’m sure you understand that using html editors can sometimes be slippery ride. You don’t always get the results you want. Sometimes your website turns into a forest of unexplainable and uncontrollable mush. And more often than not, this is not the fault of the html editor either.

So the first tip is simply to use the helpful Kompozer forums as much as possible. Don’t be afraid to ask incredibly basic questions. You’d be surprised how many other people are thinking the same thing and who would like to know the answer too! If you don’t understand why your html is not behaving like good html should, then all you need to do is ask. :)

To find the Kompozer forums just search for forums of that name. Honestly, I couldn’t have done without these forums to get me started. I’d ask a question, get a helpful reply, and then ask another question, get a reply, and so on… Until finally it clicked and I’d be one step closer to creating my perfect website again!

And here’s another tip you can take to the bank. Whenever you find a nice looking website that you like the look of, then ‘open the hood’ and look at the source code of that website. You’ll learn a LOT from doing this… Right at the start you might not be able to make sense of what you see. But as you progress you’ll start to see how the ‘engine’ works. It’ll become clearer as you go, believe me.

So, in a nutshell, to avoid the inevitable frustrations that come with playing around with free html editors, utilize the expert help at the Kompozer forums, learn from looking at how other websites do it, and make sure you keep well rested. Good luck. :)

Martin Hurley helps Kompozer newbies become instant experts at http://kompozervideosclub.com Visit now to start building great looking websites using a brand new range of Kompozer how to videos and get a 5 lesson quick start coaching session thrown in!

Like many web content authors, over the past few years I’ve had many occasions when I’ve needed to clean up a bunch of HTML files that have been generated by a word processor or publishing package. Initially, I used to clean up the files manually, opening each one in turn, and making the same set of updates to each one. This works fine when you only have a few files to fix, but when you have hundreds or even thousands to do, you can very quickly be looking at weeks or even months of work. A few years ago someone put me on to the idea of using Perl and regular expressions to perform this ‘cleaning up’ process.

Why write an article about Perl and regular expressions I hear you say. Well, that’s a good point. After all the web is full of tutorials on Perl and regular expressions. What I found though, was that when I was trying to find out how I could process HTML files, I found it difficult to find tutorials that met my criteria. I’m not saying they don’t exist, I just couldn’t find them. Sure, I could find tutorials that explained everything I needed to know about regular expressions, and I could find plenty of tutorials about how to program in Perl, and even how to use regular expressions within Perl scripts. What I couldn’t find though, was a tutorial that explained how to open one or more HTML or text files, make updates to those files using regular expressions, and then save and close the files.

The Goal

When converting documents into HTML the goal is always to achieve a seamless conversion from the source document (for example, a word processor document) to HTML. The last thing you need is for your content authors to be spending hours, or even days, fixing untidy HTML code after it has been converted.

Many applications offer excellent tools for converting documents to HTML and, in combination with a well designed cascading style sheet (CSS), can often produce perfect results. Sometimes though, there are little bits of HTML code that are a bit messy, normally caused by authors not applying paragraph tags or styles correctly in the source document.

Why Perl?

The reason why Perl is such a good language to use for this task is because it is excellent at processing text files, which let’s face it, is all HTML files are. Perl is also the de facto standard for the use of regular expressions, which you can use to search for, and replace/change, bits of text or code in a file.

What is Perl?

Perl (Practical Extraction and Report Language) is a general purpose programming language, which means it can be used to do anything that any other programming language can do. Having said that, Perl is very good at doing certain things, and not so good at others. Although you could do it, you wouldn’t normally develop a user interface in Perl as it would be much easier to use a language like Visual Basic to do this. What Perl is really good at, is processing text. This makes it a great choice for manipulating HTML files.

What is a Regular Expression?

A regular expression is a string that describes or matches a set of strings, according to certain syntax rules. Regular expressions are not unique to Perl – many languages, including JavaScript and PHP can use them – but Perl handles them better than any other language.

In part 2, we’ll look at our first example Perl script

John Dixon is a web developer working through his own company John Dixon Technology. As well as providing web development services, John’s company also provides free open source accounting software written in PHP and MySQL.

It is best not to put any JavaScripts inside a web page. Placing JavaScripts inside a web page can cause clutter. Search engines normally cannot reach important content and information if you have a cluttered web site.

JavaScript is an object-oriented scripting language used to enable programmatic access to objects within different applications. It is normally implemented as an integrated component of the web browser, allowing the development of enhanced user interfaces and dynamic websites.

Despite the name (JavaScript), it is essentially unrelated to the Java programming language even though the two have numerous similarities. JavaScript is a trademark of Sun Microsystems. It was used under license for technology invented and implemented by Netscape Communications and current entities such as the Mozilla Foundation.

Search Engine Optimization professionals suggest to place all JavaScripts in an external file. It is best to use external JavaScripts for various reasons. According to Search Engine Optimization for Dummies: 3RD edition by Peter Kent, these reasons include:

They’re safer outside the HTML file – they are less likely to be damaged while making any changes to the HTML
JavaScripts are easier to reuse – simply store the script externally and change the external file to automatically change the script in any number of pages
They are easier to manage externally – place all of the scripts in one directory for better organization
The download time is slightly shorter – If you use the same script in multiple pages, the browser downloads the script once and caches it.
Doing so removes clutter from your pages!

About CODANK Charlotte Web Design

CODANK is a top Charlotte Web Design and Internet Marketing Company located in Charlotte, NC. The company is dedicated to providing a broad range of web design services. CODANK specializes in Search Engine Optimization (SEO), Graphic Design, Online Marketing, and Web Design and Development.

For more information, visit CODANK Charlotte Web Design and Internet Marketing Company at www.codank.com

About CODANK Charlotte Website Design and Markjeting Company CODANK is a top rated Web Design and Internet Marketing firm located in Charlotte, NC. We are dedicated to provide the highest quality, cost effective custom software development services, delivering a broad range of business consulting and outsourcing services. For more information, visit us at http://codank.com

If youâ??re looking to customize your MySpace pages and you have absolutely no idea how to code them using HTML, you can still go about it by making use of the pre-made layouts and backgrounds which are available freely on the internet. You can then use the provided HTML codes for MySpace to change and customize your profile pages.

There is no hard and fast rule saying that you must change your MySpace pages, but you know that the better you make your profile pages look, the more people who will look over it, and the more your friends and family will also be attracted to it, (if thatâ??s what you want of course!).

And since not every one of the forty million plus members currently to be found on the MySpace pages will be able to code using HTML, the use of these readymade layouts and such can be somewhat heaven sent, to many people.

Added to that, you will find that itâ??s also quite simple to add these free HTML codes for MySpace, and that you can change the look of your pages quite frequently if you want to, as well. All you need to do is to follow the provided instructions on how to go about using the provided free HTML codes for MySpace, and you will be able to easily and simply place the code into the correct place.

This is normally accomplished by going through the Edit Profile section, where funnily enough, you will find that you have at your disposal everything that you need to edit, change and update your profile.

You will then be able to customize your MySpace pages using not only the HTML codes for MySpace backgrounds, and layouts, but also HTML codes for MySpace page graphics, icons and even pictures.

And if you search a little bit more you will even come across HTML codes for MySpace games, as well as HTML codes for MySpace music and music video uploads. Although the later can be accomplished quite easily if you use the music and the music videos provided on the MySpace Music pages, the HTML codes for MySpace games needs to be taken from these websites.

And after that, itâ??s all a hop, skip and a jump to customize your MySpace pages to reflect your personal tastes and characteristics. All of these can of course, for the most part be accomplished without having to use any of the pre-made layouts etc. and their HTML codes for MySpace, but in the long run, it can be very much easier on you to use them.

Muna wa Wanjiru is a Web Administrator and Has Been Researching and Reporting on Myspace for Years. For More Information on Html Codes For Myspace, Visit His Site at Html Codes For Myspace

The aspiring small-scale entrepreneur wanting to go global and online from a small regional business would invariably need a website the website needs to be functional, accessible and attractive so as to encourage the potential customers. The php-shopping cart is the need of the hour – regardless of whether the potential customer wants to add, update or delete from the list. The php cart should ideally be familiar to the potential customers.on the internet considering that the customer would opt for a familiar option rather than striving to learn a new system. The more effective php cart needs to have a textual message on each page which could be an intimation to the user as to the number of items present in the php shopping cart and on clicking on the message the customer would gain access to the number and details of items in the php shopping cart.

Creating A Php Shopping Cart

The creation of a php-shopping cart is surprisingly simple and when done with precision it could translate into a highly effective and universally accepted php-shopping cart. The details of the stocks are predictably stored in the database and the only information required from the patient which would in turn need to be stored is none other than the id of each product that has been added to the php shopping cart. The php-shopping cart is accessible and there are a variety of ways of reaching it – the most popular being the clicking on a link or by clicking on the ‘add to cart’ option on the product page. In the event of the php-shopping cart being arrived at using the link on the product page – ‘add to cart’ – the need of the hour is undoubtedly to update the products in the php-shopping cart before the display of a new product range.

It is not uncommon for the php-shopping cart to have more than one of a kind of any particular product, which could be compiled, and it is not advisable to list the number of products of a particular kind in the php-shopping cart. There is a commonality between the links to ‘delete’ or ‘add’ a product to the php-shopping cart. The customer could well have the option of updating the products in the php shopping cart – manually! The php shopping cart is seldom empty and if it is an appropriate message needs to be flashed to the effect. This is one aspect of the php-shopping cart, which can scarcely be negotiated

The Traits Of A Php Shopping Cart

The traits of a successful PHP shopping cart is predominantly that of – having the requisite information sent to cart. The php-shopping cart has the ability to locate and execute a high compliance php-shopping cart. The php-shopping cart has the inherent ability to call an external php file to say the least. The most popular of the options available is none other than the ability to pay by ‘pay pal’ the php-shopping cart then is a boon when used judiciously and history when ignored!

If you are not familiar with html codes for MySpace profiles, you are missing out on a lot of fun and practical applications that you can use to customize your site.  The number of things you can do with them is astounding.  A simple search on the Internet will generate thousands of various tools and functions that can be accomplished with MySpace html codes.  In addition to the fun and functionality, the added benefit is that the majority of html codes for MySpace that are found on the Internet today are completely free of charge.  Considering how many there are, this is pretty amazing.

So now that you know that free html codes for MySpace exists, what can you do with them?  The answer is pretty much if you can think of it, it exists.  From adding fun tidbits to your site to practical additions, MySpace html codes enable you to customize your page in the exact manner you want it to be.  MySpace profiles come as is with various features and functionalities that are pre programmed into the site.  There is very little customization that occurs from the MySpace tools provided at the site.  However, other sites have a variety of html codes for MySpace that will turn your humdrum page into a funky showcase of your unique personality.

Do you want to hide portions of your page?  You can do this even though it is not the default settings at MySpace.  There are MySpace html codes that will allow you to hide any section on the page including comments, contacts, schools, networking and more.  How about adding special characters, marquees or colors to your site?  With codes for MySpace you can do all this and more!  If you are looking for MySpace html codes check the Internet and find the exact functionality you want. 

Another added advantage of html codes for MySpace is that the majority of the ones you find will either be free or they will be share ware, a voluntary donation for use of the product.  However, for teens and younger adults, free MySpace html codes are the ideal solution to ensure a completely customized page without having to spend a lot of time on creating it.

There are so many cool things you can do in the world of social media using hmtl. We have tons of cool html codes for MySpace that you will love. Our MySpace html codes are easy to learn and you’ll have a blast customizing your MySpace profiles.

CSS is the simplest way to create attractive, quality web pages. Unfortunately, many people are still attempting to control the structure and presentation of their web pages with only HTML. Here are four reasons that you should forget about tables and start using CSS today:

Browser Compatibility-If you are trying to use tables to control the appearance of your web site, you may be able to achieve the exact look you want on a single browser (such as Internet Explorer). However, when people visit your web site with browsers like Firefox, Opera or Safari, your layout may be completely broken. If you want to make sure that users from any browser get the best experience from your web site, you need to start using CSS. Although it’s not perfect, CSS will ensure that visitors don’t leave your web site because of a broken layout.

Easier to Update-Wouldn’t it be nice to change the font color with a single line of code? With CSS, it really is this simple. Although updating the appearance of a large web site that only uses HTML can take days or weeks, CSS keeps all your style information on a single page.

Faster Load Times-By using an external .CSS file, you can significantly reduce the load time of every page on your web site. This is because a browser can cache all of the style information for your pages instead of needing to load every tag over and over again.

More Attractive Pages-This is probably the most obvious advantage of CSS. CSS can accomplish things that a HTML only web page could never even come close to doing. CSS really does give you complete control over how you want your web site to look. An well-designed web site will always be perceived as more reliable than one that does not look professional.

To keep up with all the latest news and information throughout the webmaster community, make sure to visit and bookmark the Daily Web Dev Blog.