Skip to content

Switch between PHP versions on OS X Mountain Lion

Is it possible to have multiple versions of PHP installed on OS X Mountain Lion and freely change between them? Similar to the way MAMP allows you to. I’m wanting to get out of using MAMP and this is really the only feature holding me back. Answer Here’s a great blog post about Maintaining two ver…

Stop using `global` in PHP

I have a config.php that is included to each page. In config I create an array that looks something like: $config = array(); $config[‘site_name’] = ‘Site Name’; $config[‘base_path’] = ‘/home/…

How can i “merge” these two regular expression in PHP?

I’m learning regular expression, so please go easy with me! Username is considered valid when does not start with _ (underscore) and if contains only word characters (letters, digits and underscore itself): In order to merge them in one regular expression, i’ve tried the following: To be read as: …

php get values from json encode

I have an url passing parameters use json_encode each values like follow: $json = array ( ‘countryId’ => $_GET[‘CountryId’], ‘productId’ => $_GET[‘ProductId’], ‘status’ => $…

How do I make this preg_match case insensitive?

Consider: preg_match(“#(.{100}$keywords.{100})#”, strip_tags($description), $matches); I’m trying to show only 100 characters in each side with the search string in the middle. This code actually …

search associative array by value

I’m fetching some JSON from flickrs API. My problem is that the exif data is in different order depending on the camera. So I can’t hard-code an array number to get, for instance, the camera model …

isset vs empty vs is_null

I’m trying to write a script that when a user uploads a file and does not enter a name an error is returned. I’ve tried using is_null, empty, and isset and they all do not work. Eg, below, is_null …