Skip to main content

Posts

Showing posts from October, 2020

Text Manipulation

Today I want to share with you a few powerful examples of what you can do with ES6 - and a little out of the box thinking, and how much it will allow you to quickly scale up in a clean fashion. Cleaning Strings This for me was one of those "a Ha!" moments where the answer was just staring you in the face.  I had to include it since you may typically you might think to use some elaborate library.  Take the scenario where you present the user with an input box that allows for rich text, but you want the cleanest way to only store non-unicode characters.  Try this simple one-line gem: myCleanString = "test-_aaa'#@".replace(/[^0-9a-zA-Z-_' ]/gi, ''); The regular expression in this statement effectively says that for any characters not in this group (0-9, a-z, A-Z and symbol's hyphen, underscore, single quote and space), replace them with an empty string.  Do this for the characters of your choosing. DB Inserts/Updates Here I like to use the power of

Low Level Debugging

Here's a small tip which I found extremely useful when I came across this type of (loosely) documented crash.  The problem is, it is extremely difficult to know at what point it crashed as there is no stack trace as part of it.  Likely as well (as in my case), it was in a vendor component (composer, etc.) which was designed for a different version of PHP. Well, here's the answer.  This guide shows how to create a simple script to include in to your program, which will echo out a filename and line for each " tick " that PHP is processing.  The last one it gets to before it crashes -- bingo, you know what's causing the problem! Hope this helps!