Archive for the ‘how to’ Category

PHP Command line interface, set and read ENV variables

When a variable on the console is set export VARIABLE=VALUE; You can get it from PHP Command line (CLI) using getenv(‘VARIABLE’)   Example #script.php <?php var_dump(getenv(‘VAR’)); ?> From command line php -f script.php //bool(false) export VAR=a; php -f script.php //string(1) “a”  

Xdebug debug with Netbeans on Linux

XDebug is a free PHP extension to debug variables of your applications. Combined with Netbeans for PHP debug features (break points, variable watching and flow execution navigation, see screenshot on the left), it allows to have a complete debug environment. What it’s really interesting is the possibility to place breakpoints in any file, even though [...]

Chrome and Internet Explorer ignore Windows hosts file

I’ve recently had some issue with local websites (in addition to ” localhost”->127.0.0.1). Chrome and Internet Explorer didn’t use the hosts file to solve the other local addresses (e.g: “zendapp.localhost”->127.0.0.1) I’ve previously set. I’ve had this problem on Windows Seven. After some googling its seems that the issue is not OS-dependent but it’s a default [...]

Upload a tree of files and subdirectory to a remote FTP server

I’ve recently been asked to move a site (1Gb of files) from a Italian hosting linux (no ssh) to the same cheap hosting but to another server windows (damn ! no ssh, no console commands from PHP, the only way to upload files is the old slow uncool FTP). Problem: I’ve got an extremely poor [...]

How to search complex source code using regular expressions

Today I needed to search the source code that ware calling a function with a complex array of parameters URL::Make( ‘site/store.inc.php’, array( ‘action’=>’view’,’id’=> [... STH...] ,’idTwo’=> [... STH...] ) ); Considering this requirements: – there are lots of similar function (to exclude from the search) with an argument less or an argument more – there [...]

UTF8 in LAMP applications: overview and how to solve the common issues

The problem In a LAMP application the text is frequently saved/retrieved from/to a database and files. We must consider all the different encoding (mapping characher-byte value): latin1 iso8859-1, latin9, UTF-8 (utf8) etc… Lots of applications use ISO8859 encoding and some PHP functions to convert the characters (htmlentities, htmlspecialchars etc…) The solution Converting all the text [...]