All In One Script
MENU

How to extract a file extension in PHP?

by 4:19:00 AM
undefined
How to extract a file extension in PHP? This is a question you can read everywhere on the web with various answers : $ext = end(explode('.', $filename)); $ext = substr(strrchr($filename, '.'), 1); $ext = substr($filename, strrpos($filename, '.') + 1); $ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename); $exts = split("[/\\.]", $filename); $n = count($exts)-1; $ext = $exts[$n]; etc. However, there is always "the best way" and it should be on stackoverflow. solution: People from other scripting languages always think theirs is better because they have a

How to get the current date and time in PHP?

by 4:18:00 AM
undefined
How to get the current date and time in PHP? Which PHP function can return the current date/time? BEST Solution : The time would go by your server time. An easy workaround for this is to manually set the timezone by using date_default_timezone_set before the date() or time() functions are called to. I'm in Melbourne, Australia so I have something like this: date_default_timezone_set('Australia/Melbourne'); Or another example is LA - US: date_default_timezone_set('America/Los_Angeles'); You can also see what timezone the server is currently in via: date_default_timezone_get(); So something like: $timezone = date_default_timezone_get(); echo "The

Get first key in a (possibly) associative array?

by 4:15:00 AM
undefined
Get first key in a (possibly) associative array? What's the best way to determine the first key in a possibly associative array? My first thought it to just foreach the array and then immediately breaking it, like this: foreach ($an_array as $key => $val) break; Thus having $key contain the first key, but this seems inefficient. Does anyone have a better solution? Answer : You can use reset and key: reset($array); $first_key = key($array); It's essentially the same as your initial code, but with a little

What is the difference between single-quoted and double-quoted strings in PHP?

by 4:14:00 AM
undefined
What is the difference between single-quoted and double-quoted strings in PHP? I'm not an expert in PHP programming, but I'm a little confused why I see some code in PHP with string placed in single quotes and sometimes in double quotes. I just know in .NET, or C language, if it is in single quote, that means it is a character, not a string. Solution: PHP strings can be specified not just in two ways, but in four ways. Single quoted strings will display things almost completely "as is."

Dude, where's my php.ini?

by 4:11:00 AM
undefined
Dude, where's my php.ini? A few years ago I installed Apache 2.2x and PHP 5.3.1 on a Linux server I maintain. I used .tar.gz's and built them as instructed (instead of rpms and what-have-you). And all was fine. Today I need to install this which seems like a PHP library. I went through all the steps up to make install, and I find ibm_db2.so in $PHP_HOME/lib/extensions/somecomplicatedname/ibm_db2.so The great catch is the last step is to configure php.ini but there is NO php.ini on my system. Horror of horrors.

How to 'insert if not exists' in MySQL?

by 4:10:00 AM
undefined
How to 'insert if not exists' in MySQL? I started by googling, and found this article which talks about mutex tables. I have a table with ~14 million records. If I want to add more data in the same format, is there a way to ensure the record I want to insert does not already exist without using a pair of queries (ie, one query to check and one to insert is the result set is empty)? Does a unique constraint on a field guarantee the insert will fail

How to check if PHP array is associative or sequential?

by 4:06:00 AM
undefined
How to check if PHP array is associative or sequential? PHP treats all arrays as associative, so there aren't any built in functions. Can anyone recommend a fairly efficient way to check if an array contains only numeric keys? Basically, I want to be able to differentiate between this: $sequentialArray = array('apple', 'orange', 'tomato', 'carrot'); and this: $assocArray = array('fruit1' => 'apple', 'fruit2' => 'orange', 'veg1' => 'tomato', 'veg2' => 'carrot'); Answer : You have asked two questions that are not quite equivalent:

Instagram