I was working on a Laravel project and had to work with a Eloquent ORM object; I then needed to create an empty stdClass object. There's a chance that a person is not known and being lazy I wanted to fill the form anyway with my Person object, so I needed a mockup of that object. <?php $person = (object) array_fill_keys( array('firstname', 'lastname', 'email', 'photo'), '' ); ?> I'd say this solution is quick and dirty.💬 Read more
I wanted to get the IPv4 range of a WHOIS record provided by LACNIC, because unlike other RIRs they don't supply you with the range, but with just a CIDR notation. To make matters worse, they give 'incomplete' net numbers. The only working "CIDR to IP range" function I could find didn't accept it, so I had to sprinkle some magic. <?php $ipdata = explode('/', ltrim($incomplete_cidr_notation, '0')); $dotcount = substr_count($ipdata, '.💬 Read more
To go along nicely with my previous Shoutcast tip, here is a trick to separate the data in the Shoutcast 7.html for displaying. If you, like me, use the Shoutcast 7.html trick to get some quick stats about your stream broadcast but are getting some inconsistencies with parsing the comma-separated input you get, try this: <?php $data = preg_split("/[,]+/", $string, 7); ?> A possible outcome would be this: <?php Array (  => 1  => 1  => 1  => 1000  => 1  => 192  => "Woe, Is Me - Hell, or High Water" ) ?💬 Read more
Pretty semantic title, huh? But that's basically what this is all about. Shoutcast logo If you have a Shoutcast host that is set to private, only people whose IP address in the RIP list (Reserved IP) can access your stream. A lot of free Shoutcast server providers do this, to make it a bit less profitable to free ride their services. Let's have a quick look at the code and then analyze it to understand what it's doing.💬 Read more
This blogpost is for historical purposes. There is a better way with array_splice. At work today, my colleague needed to add, or rather 'insert', a value into an existing array AND on a specific index. This because we fed it into a JS table sorter, once we pulled it through json_encode(). So what we really required: array_push_insert We couldn't find any existing Array function at php.net, so I decided to make my own version.💬 Read more
I’m a 34-year old software engineer from The Netherlands. My interests lie with (web)development, databases, design patterns, social media, communities, APIs and open data.
More about me, including links to other online services, can be found at gerben.dev