Report inadequate content

Php in Harecoded


A true multiline regexp in PHP. The "I miss U" technique

The following regular expression matches tags that are opened and close in different lines, albeit can be used for any other purpose. It is also ungreedy, meaning that when the first closing tag is found the rest of equal tags will be ignored.

It is very easy to remember and to apply, I call it the "I MISS YOU" technique, see the why in the regexp modifiers: ...


Features in PHP 5.4

We had to create a file upload form that allows a user to upload big files. In order to keep a good experience for the user we decided to show the progress bars.

There are several ways of doing that but it came to my mind that PHP 5.4 had an improvement on file upload, making it easier now and wondered if I had the last excuse to upgrade the servers from 5.3 to 5.4.



Apache RewriteCond -f check file exists solution

If your Apache virtualhost or htaccess configuration uses a rewrite condition (RewriteCond) in order to allow nice URLs, you should be aware that since Apache 2.2 the "check if file or exists" works a little bit different. Any of the following examples might have stopped working for you:

   RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d


Llamadas cURL a través de distintas interfaces

Si tu servidor web dispone de varias interfaces de red y quieres que ciertas peticiones que haces con cURL salgan a través de una IP específica puedes modificar el flag CURLOPT_INTERFACE de cURL pásandole la IP.

Un ejemplo tonto podría ser:

// Todas mis interfaces de red:
$interfaces = array(


Smarty: Concatenation of variables inside block parameters

In Smarty sometimes you need to concatenate 2 variables and pass it as a single variable inside a block. But the placeholder won't allow any expected PHP syntax

You want to accomplish something like:

{assign var="MYVAR" value=$variable1.$variable2}

But, the dot in smarty is for array access, so, what about...

{assign var="MYVAR" value=$variable1+$variable2}

No. It does...


How to setup a remote development environment over SFTP (working copy)

This article explains how to setup the server and client to work with a remote working copy.

To properly understand this post you should have read the previous post, When to setup a remote development environment over SFTP (working copy).

To have the enviroment up and running you must setup once the server, and then apply the configuration of the client in every ...


When to setup a remote development environment over SFTP (working copy)

When a programmer has a local copy of the code and an environment fully functional where the web can be tested before going live, we usually call it a working copy.

The action of moving/copying/putting this work in the final live server (a.k.a production server/environment) is called the deploy action.

There are many ways of having a working copy up and running. We, the...


Merge Json files

With this small script you could merge some json files in a new one in json validated format.  The script uses each file name like array key.

Look the example:






Whit our script you could run:

php merge_jsons.php file1.json...


Convert a CSV to JSON with PHP

Imagine a data list dumped in a plain text file (e.g: CSV) and you need to convert it to JSON format. You could use this simple php script to do such task.

It's the simplest version but from here you can customize it to fit your requeriments.


php script_name.php file_to_convert.csv > result.json

The script:

$csv = file_get_contents( $argv[1] ); $csv =...


Instalar PHP 5.3 en CentOS

Me tienen contento!

Hace muchísimo que deberían haber incluído la versión de PHP 5.3 en los paquetes php por defecto de CentOS, pero parece que se van a quedar con la 5.2 hasta el fin de los tiempos. Ofrecen la versión 5.3 como un paquete separado (php53), lo que implica desinstalar PHP y librerías asociadas para reinstalar la 5.3 con este paquete distinto (incompatible...