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’ => $…
Show user’s total comment count outside The Loop in WordPress
How do I display a user’s total comment count outside The Loop? I use this code to display comment count inside the loop: That works fine inside the loop. In an attempt to make that code work outside the loop, I changed $user_id = $post->post_author; to $user_id = get_the_author_meta( ‘ID’…
Flip associative array and store new values in subarrays to prevent losing duplicated values
I have a flat associative array which may contain duplicate values. I need to restructure the data to store the original values as new keys and the original keys pushed into subarrays associated with the new keys. Answer
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 …
PHP How to echo without HTML tags
I have a sort of system where everybody can type whatever he wants. Though, they can also seem to use tags like , etc. How …