Archive for the ‘PHP’ Category


I need to break a paragraph into lines that are no longer than 60 characters for a particular, text-only email template.  I want the lines to break at/on spaces (because just breaking at the 60th character would probably cut words in half, randomly… not very professional!). (more…)


All I want is to convert a super-simple SimpleXML object to an array.  “super-simple” means no attributes, etc.  Nothing that is XML-specific.

$xml_string = "
        <sub_first_thing_a>Hi, I am the content of the first thing.</sub_first_thing_a>
        <sub_first_thing_b>Hi, more content.</sub_first_thing_b>
    <second_thing>Notice, no attributes or anything fancy.</second_thing>
$simplexml_object = simplexml_load_string($xml_string);


Why?  Because a number of functions, libraries, etc. return SimpleXML objects.  For example, the 1.x version of the very-awesome AWS PHP SDK tends to return SimpleXML objects.  And 9 times out of 10 all I need is a multi-dimensional, usually keyed (associative) array. (more…)


Quite simply, a great post on creating a basic yet highly usable/functioning ICS file in PHP.  The result is a ‘please download or pick a program that can open this file’ dialog. (more…)

Came across this amazing, simple feature in PHP Strings: How to Get the Extension of a File by “Stoimen” where the problem of getting a file’s “extension” is solved simply.

Instead of: substr($filename, strrpos.....
use: pathinfo($filename, PATHINFO_EXTENSION)

Best part is that this uses PHP to get the extension of a file. As the author notes, this lets us rely on really smart people who have to do a good job.

EQUALLY great are the two comments (as of my posting this):

What I love about this simple, single post is that I learned about pathinfo, end, and have yet another tool in my SPL toolbelt. Awesome.


Problem: The output of PHP’s htmlentities() is seldom valid XML.  As I am attempting to make KML maps for Google Maps, I have run into a problem where various names use UTF8 valid characters that are not very HTML friendly (ex. the ‘n’ with a tilde in daño — not sure if that shows up in your browser or not but the ‘n’ should have a squiggly line over it). (more…)