Quickly create an empty stdClass object in PHP

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 more
Get IP range by CIDR notation

Get 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 more
Perfect separator for Shoutcast 7.html file

Perfect 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.

šŸ’¬ Read more
How to programmatically add an IP address to a Shoutcast Reserved IP list in PHP

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.

Shoutcast logo
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
array_push_insert: Push new value into array with PHP

array_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 more
Black and white picture of Gerben Jacobs
Hi!

Iā€™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

Tags

go 1 personal 11 php 5 roi-stock-portfolio 3 scandinavia-2013 3 stocks 3 tech 17 web 1 youtube 1

Socials

Meta