Archive for the ‘PHP’ Category


Convert XML Object to Array in PHP

In PHP on October 15, 2011 by patrellery

Here’s a very simple way to convert an XML Object to an array in PHP.

$string = '
    <message>Message 1</message>
    <message>Message 1</message>

$xml = json_decode(json_encode((array)simplexml_load_string($string)), TRUE);

easy no?



Find user’s timezone with PHP and Ajax

In PHP on October 14, 2011 by patrellery

Here’s a simple function to find out what is the user’s timezone in PHP

<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(document).ready(function() {
var visitortime = new Date();
var visitortimezone = "GMT " + -visitortime.getTimezoneOffset()/60;
type: "GET",
url: "",
data: 'time='+ visitortimezone,
success: function(){

and then on your php file:
$_SESSION['time'] = $_GET['time'];


How to clear redis keys

In PHP on October 2, 2011 by patrellery Tagged:

The other day we found a big issue on our development platform and we had to clear Redis memory/Keys to make sure we re-import valid data to our database.
Read More »


Split string by delimiter in PHP

In PHP on September 29, 2011 by patrellery Tagged:

Here’s a quick tip to split a string using the pipe (|) delimiter in PHP. Let’s say you have a log or some sort of non usual string you want to split, such as:

$str = 'A|B\|B|C\\|D\\\|D';

You want this to look like:

$array[0] => 1
$array[1] => 2\|2
$array[2] => 3\\
$array[3] => 4\\\|4

Read More »