|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Ads Donate Humor |
|
HTML:
Regular Expressions:
|
How to convert Amazon.com affiliate ads into valid HTML 4.01 TransitionalDid you try to validate the HTML on your web pages at W3C and get dozens or hundreds of errors because of your Amazon.com affiliate advertising code? It's fairly easy to fix the errors and make your code validate as HTML 4.01 Transitional. It cannot validate as HTML 4.01 Strict because the Amazon code uses <iframe>, which is not legal in Strict. If you are currently using Strict, revise your DOCTYPE to declare the document as HTML 4.01 Transitional. The purpose of declaring a DOCTYPE is to provide browsers with a predefined standard that tells them how your code should be interpreted and therefore how the page should be displayed. Which standard you use is not important to browsers or search engines. You need to use whatever standard renders the page properly. The important thing is to use some standard. Asking which standard is "best" is like asking whether your page should be in English or in French. It depends on who the page is for, but if you choose English, it should be written in proper English. If you choose French, it should be written in proper French. If you have a page that you cannot validate to any standard, it is better to omit the DOCTYPE altogether, rather than declare a DOCTYPE and then fail to meet it. When you don't declare a DOCTYPE, browsers go into "quirks mode" and attempt to render the page the best they can, which is usually reasonably good. When you declare a DOCTYPE, it says, "Don't use quirks mode," even if quirks mode might help render the page better. Why Amazon HTML code doesn't validateThere are two aspects of the Amazon code that must be fixed:
The rest of this article gives code examples and shows how to use Find and Replace to revise the code efficiently. I used FrontPage 2003, but other design programs such as Expression Web and Dreamweaver have similar Search and Replace methods. Amazon Product Links and Search Box LinksWhen you get your code from the Associate Central Build Links interface, it looks something like this: <iframe src="http://rcm.amazon.com/e/cm?t=YourAmazonID &o=1&p=8&l=as1&asins=B000SZZPHA &fc1=000000&IS2=1<1=_top&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> At the W3C validator, every unencoded ampersand generates 3 errors and an informational message:
The above code for one Amazon ad has 11 ampersands and generates 44 messages! The solution for the above example is to replace every & with & . Search and Replace throughout the siteIt's more difficult to do this replacement in every ad throughout a website, however. It's basically just a Find and Replace operation, but:
Fully automatedBefore you do a global Find and Replace that will have effects throughout your site, always make a backup copy of your entire website in case something goes wrong. If each of your product link ads is stored in its own include file (which is a desirable organization for other reasons), the task is easy:
I was able to make 1700 replacements of & to & with a single Find and Replace, which I was glad not to have to do manually. Partially automatedIf your situation is more complicated, you should still be able to automate it at least partially. You just need to make sure to replace everything that needs replacing, and not corrupt anything else as a side effect. If you've been consistent in how you created your product links at Amazon, most of the ad code will be the same in every ad. Text that needs revision and is likely to be the same in all your ads is shown below in green. Your ad code will not be exactly the same as this: <iframe src="http://rcm.amazon.com/e/cm?t=YourAmazonID &o=1&p=8&l=as1&asins=B000SZZPHA &fc1=000000&IS2=1<1=_top&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> It is extremely unlikely that these two strings of consecutive characters appear anywhere except your Amazon ads, so it's possible to find and replace as follows. As described in the previous section (but not here), do some "test Finds" before doing the final Find and Replace: 1) Find (the original string with ampersands): &o=1&p=8&l=as1&asins= Replace With (each ampersand replaced by an HTML entity): &o=1&p=8&l=as1&asins= 2) Find (the original string with ampersands): &fc1=000000&IS2=1<1=_top&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr Replace With (each ampersand replaced by an HTML entity): &fc1=000000&IS2=1&lt1=_top&lc1=0000FF&bc1=000000& bg1=FFFFFF&f=ifr Using a Regular Expressions Find and ReplaceEven if you have to spend a few hours learning to work with regular expressions, they are so powerful and time saving that you will eventually get all your time back, plus you'll know something new. The following is an example of a site-wide regex Find and Replace for Amazon code. Your actual search and replace strings will probably not be the same, and if there are variations in your ads (properties of the iframe, for example), you'll need to add more regex clauses to accommodate the variations. The code that makes these regular expressions is highlighted: Find: <iframe src="http\://rcm\.amazon\.com/e/cm\?t=YourAmazonID &o=1&p=8&l=as1&asins={[A-Za-z0-9]@} &fc1=000000&IS2=1<1=_top&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr" style="width\:120px;height\:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> \ means "interpret the next character as a literal instead of a special regex character". The {([A-Za-z0-9]@)} stores the product ID (which is different for each ad) to a variable so we can use it in the Replace operation. (I used FrontPage regex syntax.) Replace With: <iframe src="http://rcm.amazon.com/e/cm?t=YourAmazonID &o=1&p=8&l=as1&asins=\1 &fc1=000000&IS2=1&lt1=_top&lc1=0000FF&bc1=000000 &bg1=FFFFFF&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"> </iframe> \1 inserts the product ID at the appropriate location. Recommended Product LinksAfter converting all the ampersands as described above, also remove the text border="0", whose function is duplicated anyway by style="border:none;". The Amazon-provided code for Recommended Product Links looks like this: <iframe src="http://rcm.amazon.com/e/cm?t=YourAmazonID &o=1&p=14&l=st1&mode=books&search=neural%20networks &fc1=000000<1=_blank&lc1=3366FF&bg1=FFFFFF&f=ifr" marginwidth="0" marginheight="0" width="160" height="600" border="0" frameborder="0" style="border:none;" scrolling="no"></iframe> Text LinksText Links code has a mix of unencoded (&) and encoded (&) ampersands. Be careful to replace only the unencoded ones. Also create a value for alt, something like alt="Amazon.com": <a href="http://www.amazon.com/gp/search?ie=UTF8&keywords=artificial%20 intelligence&tag=YourAmazonID&index=books&linkCode=ur2&camp=1789 &creative=9325">Books on Artificial Intelligence</a><img src="http://www.assoc-amazon.com/e/ir?t=YourAmazon-ID&l= ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> If your Text Links are placed on individual pages rather than stored in include files, you probably will have to do the ampersand replacements manually, and cannot automate the process. Here is an automation procedure, but note step 1!
Omakase and Context LinksThese both use JavaScript and don't require conversion. TestingMake sure your ads function the same as before and watch your stats to make sure clicks are properly recorded. These articles discuss regular expressions in more detail:
Questions, comments, assistance in the Forum. |
|
|
|
|
|
|