Quickly create an empty stdClass object in PHP
š — š§® 112 words — š·ļø tech php
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.. but frankly, it's not that dirty at all!
š¬ Read moreGet IP range by CIDR notation
š — š§® 258 words — š·ļø tech php
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.
š¬ Read morePerfect separator for Shoutcast 7.html file
š — š§® 173 words — š·ļø tech php
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 (
[0] => 1
[1] => 1
[2] => 1
[3] => 1000
[4] => 1
[5] => 192
[6] => "Woe, Is Me - Hell, or High Water"
)
?>
If you were to explode()
this string, you'd get the artist in 2 nodes and with this song title you'd get that one in 2 nodes as well.
How to programmatically add an IP address to a Shoutcast Reserved IP list in PHP
š — š§® 353 words — š·ļø tech php
Pretty semantic title, huh? But that's basically what this is all about.
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 morearray_push_insert: Push new value into array with PHP
š — š§® 326 words — š·ļø tech php
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 moreIām a 36-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