Text to JavaScript Converter
This article provides a one-page text to JavaScript converter. The conversion is done with PHP. The converted JavaScript is for saving to an external file. The code for importing the file is also generated.
Upload the text to JavaScript converter on your website where it's handy for whenever you need it.
The content published with JavaScript may be a word, a phrase, a paragraph, and even other JavaScript.
Reasons For Using JavaScript
There are a few reasons to use JavaScript for publishing certain content on web pages:
A. Hiding content from robots and spiders.
JavaScript content generally is not seen by robots and may not get indexed by search engine spiders, especially when the JavaScript is imported from an external file.
-
Certain words or phrases in the content, if indexed, may have a detrimental affect on the web page's search results position.
-
Certain words or phrases in the content may cause search engine algorithms to mark the web page as a bad neighborhood.
-
If the content is an ad or something else with views counted, the logs will better represent actual views.
B. Publishing certain content only for browsers with JavaScript enabled.
Here are a few reasons for publishing certain content only if the browser has JavaScript turned on.
-
To publish links to games or other content that can work only with JavaScript.
-
To hide forms from spammers' automatic submission robots.
-
To publish content only when the page is loaded in a certain browser.
C. To defeat source code page copying thieves.
When the entire web page source code is copied for use somewhere else, the JavaScript to import an external file is also copied.
The .htaccess file can be used to take control if the web page source code is published on another domain.
The Defeating Source Code Page Copying Thieves blog post tells you how.
The Text to JavaScript Conversion Software
Here is the complete PHP web page to convert text to JavaScript.
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <title>Text to JavaScript converter</title> <style type="text/css"> body { font-family:sans-serif; margin:50px 0 50px 100px; } textarea { width:500px; height:200px; } .content,input { width:500px; } </style> </head> </body> <div class="content"> <h3>Text to JavaScript Converter</h3> <?php /* Text to JavaScript Generator Version 1.1 September 4, 2012 (Version 1.0 published March 9, 2010) Will Bontrager https://www.willmaster.com/ Copyright 2010 Bontrager Connection, LLC Copyright 2012 Will Bontrager Software, LLC This software is provided "AS IS," without any warranty of any kind, without even any implied warranty such as merchantability or fitness for a particular purpose. Will Bontrager Software, LLC grants you a royalty free license to use or modify this software provided this notice appears on all copies. */ if( isset($_POST['text']) ) { $_POST['text'] = stripslashes($_POST['text']); $_POST['text'] = rtrim($_POST['text'],"\r\n"); echo <<<FIRSTOFOUTPUT <p>The JavaScript converted from text is in this textarea box. Save it to a file with a .js extension. Upload it to your server and note its URL.</p> <form><textarea name="text" onclick="select()" wrap="off"> FIRSTOFOUTPUT; foreach( explode("\n",str_replace("\r",'',$_POST['text'])) as $line ) { $js = str_replace("\\","\\\\",$line); $js = str_replace("'","\\'",$js); $js = str_replace("<!--","<'+'!--",$js); $js = str_replace("-->","--'+'>",$js); $js = preg_replace('/(scr)(ipt)/i','$1\'+\'$2',$js); $js = preg_replace('/(win)(dow)/i','$1\'+\'$2',$js); $js = preg_replace('/(doc)(ument)/i','$1\'+\'$2',$js); $js = preg_replace('/(text)(area)/i','$1\'+\'$2',$js); $js = preg_replace('/(fo)(rm)/i','$1\'+\'$2',$js); echo "document.writeln('$js');\n"; } echo <<<LASTOFOUTPUT </textarea> <p style="margin-top:25px;">The JavaScript to import the file into your web page is in this textarea box. Replace the src= URL with the URL to the above file on your server.</p> <textarea name="text" style="height:50px;" onclick="select()" wrap="off"> <script type="text/javascript" src="https://example.com/file.js"></script> </textarea></form> <hr style="margin:35px;"> LASTOFOUTPUT; } ?> <p> Type or paste the text to convert into this textarea box. </p> <form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>"> <textarea name="text" wrap="off"><?php echo(@$_POST['text']); ?> </textarea> <p> <input type="submit" value="Convert text to JavaScript"> </p> </form> </div> </body> </html>
The above needs no customization.
Save it as any web page file name ending with .php and upload it to your server. To use the software, type the its URL into your browser.
Example Installation
Here is an example of the above text to JavaScript PHP web page in action: Text to JavaScript Converter
Perhaps some of the reasons to publish content with JavaScript given in this article are reasons that affect your website.
If yes, use the above example installation or install the JavaScript converter on your server to convert the relevant text into JavaScript.
Will Bontrager