PHP Utility to Convert Multi-line MySQL Strings

Posted by & filed under , , .

php-med-transThis is a very small “project” (I use quotes since the term “project” seems a bit generous here, however, it is treated as a project on GitHub!), which I found to be useful when dealing with generating MySQL scripts to insert or update text which spans over multiple lines. In most such cases, I would manually had to go and “format” the value such that apostrophes are escaped, new lines get replaced with \n and all these annoying little things to make my SQL statement valid and not fail.

In time this gets tedious and time consuming (not to mention the fact that my patience has very short limits! :D) — so I finally got off my bum and put together a short PHP script to automatically perform such a conversion.

As with most of my utilities I work on, they end up on GitHub or SourceForge — this one can be found here: https://github.com/liviutudor/MySQLMultiLineString and hopefully the README file contains enough information. You can also see it in action, live, on my website, following this link: http://liviutudor.com/mysql_multiline.php . The concept is pretty simple: take the input text, apply some basic regex replace (things which I used to do manually) and spit the result back.

Hope it’s not just me who finds this useful 🙂 Any comments/etc either drop me a line or use the “Issues” facility on GitHub to log an issue against this project.

Leave a Reply

Your email address will not be published.