Convert UTF-8 Characters to &-Encoded HTML Entities

Nowadays, most websites and web servers should serve UTF-8 characters. But, some still don’t. So, when you’re provide a web service that is to be consumed by a third party and your content appears crappy because you’re UTF-8 characters became garbled somewhere along the way, you can convert them to &-encoded HTML entities by using PHP’s mb_convert_encoded() function. For example, you can pass your entire HTML source code for a page through the function and then pass it again through PHP’s htmlspecialchars_decode() function to convert special HTML characters (<, >, etc) back to special characters so the page renders correctly in a browser.

// convert special characters to HTML entities
$htmlsourcecode = mb_convert_encoding($htmlsourcecode, "HTML-ENTITIES", "UTF-8");

// revert HTML characters back from HTML entities
$htmlsourcecode = htmlspecialchars_decode($htmlsourcecode);

Force WinSCP to Transfer Files With Certain (LF / CR) Line Endings

If you’re using WinSCP as a file synchronication /transfer tool, you’ll be disappointed to find out that it doesn’t handle line endings correctly. For example, you may download a file from a linux server with Unix line endings (LF) to your local Windows machine but the file on your system shows CRLF line endings. Even if you set the end of line character to LF in the WinSCP Environment settings, it still doesn’t handle line endings correctly.

To ensure correct line endings when you transfer files, you need to force the transfer mode to BINARY which works for text / code as well.

 

Using jQuery to Screen Scrape HTML From a Different Site – jQuery cURL

Javascript cross-domain policies prevent us from calling remote sites from our pages. Here’s a nice tutorial that shows you how to overcome that so that you can effectively cURL a remote web page to your calling javascript for local processing and/or screen scraping.

http://usejquery.com/posts/the-jquery-cross-domain-ajax-guide

http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/

https://github.com/padolsey/jQuery-Plugins/tree/master/cross-domain-ajax

PHP & Javascript IDE

Every now and then I like to search for useful tools that make it easier to do web development. Most recently, my biggest improvement was switching my IDE from Dreamweaver to Sublime Text 2. Now, I just came across a couple of IDEs designed specifically for PHP and Javascript,  the of the most often-used languages for web development. They look good but I haven’t had a chance to try them out. Here they are: