Using PHP to Add Content to Plain Text

In my last blog message, I described how I use a converter to HTML-ize plain text. This is useful for taking URLs like http://www.eilertech.com/work/resume.htm and producing a link. Now that I convert each text file before display, I can add content.

One thing I add to my web pages, is ads. Some people pay me for specific ads. On other pages, I put in filler from Google Ads.

I based my converter on functions from snippets.dzone.com, particularly "txt2html". At the end of that function, when the HTML is almost ready, I can append to it. Or, since I want the ads up front, I pre-pend.

/* Ad from adsense.google.com.  Get your own ad from there, 
 * unless you want me to get paid for it! 
 * When you have the ad, they'll tell you what HTML to put in your site.
 * Cut and paste their text into the string below.
 * Put only double quotes inside the string, single quotes to define it. */ 
$html = '<' . 'table align=right> <' . 'tr> 
<' . 'td> <' . 'script type="text/javascript"><' . '!--
google_ad_client = "pub-4220969454236754";
/* 300x250, created 10/17/09 */
google_ad_slot = "6246428593";
google_ad_width = 300;
google_ad_height = 250;
//-->
<' . '/script>
<' . 'script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
<' . '/script>
<' . '/td> 
<' . '/tr> <' . '/table>' . $html;
		
return $html;

About the Author: 

Scott Eiler has for decades worked in all aspects of software engineering, in public and private sectors, in many different industries, on projects most people know by name, as employee, vendor, and now consultant. He also maintains his own diverse web site, including much commentary. Scott knows, engineering is more than just hacking out code.

Posted in: 
Development
Bookmark and Share

Comments

Comments

Content vs. Other Content

If you put too much other stuff (like pictures) in your web pages, you do have to be careful where you put the auto-generated stuff (like ads). On my own pages, I've moved the ads to wrapper files, which act as header and footer for the translated plain text. I'll talk about that in a future article.