Simple one, I was just wondering if there is a clean and eloquent way of returning all values from an associative array that do not match a given key(s)? This is what I’m (going to be) using, however, are there cleaner implementations, something I missed in the manual perhaps? Answer You could just unse…
Tag: php
best practice in mysql?
I need to store historical data for something in mysql (only last 7 days) – should I just make an extra column for each or what is the acceptable way to?
print an array as code
I want to convert a big yaml file to PHP array source code. I can read in the yaml code and get back a PHP array, but with var_dump($array) I get pseudo code as output. I would like to print the array as valid php code, so I can copy paste it in my project and ditch the yaml. Answer
zipArchive with MAMP?
trying to work out how to install zipArchive extension with MAMP, but not having much luck any know how to do this? I have no idea Answer Answering my own question for completeness. JUST UPGRADE MAMP!!! Sorry for shouting 😉
Stripping a string of its non-numeric characters
I have a phone number stored in $phone, it looks like this: (555) 555-5555. I want it to look like this: 5555555555. How do I take the string and strip it of hyphens, spaces, and parenthesis? Answer With a regexp. Specifically, use the preg_replace function:
How can I make sure a float will always be rounded up with PHP?
I want to make sure a float in PHP is rounded up if any decimal is present, without worrying about mathematical rounding rules. This function would work as follows: 1.1 to 2 1.2 to 2 1.9 to 2 2.3 to …
php include prints 1
i code the following When I use the include function in conjunction with a function that’s designed to output to the page (e.g., or echo include ‘foo.php’), it returns the include but with a “1” after the content that has been included. Answer should be
PHP some $_POST values missing but are present in php://input
I have a very big html form (containing table with rows, which contain multiple inputs), which i need to submit to PHP script via POST request. The problem is some values don’t come through and are …
The PHP error log has stopped working. It did work
It’s been working for ages and stopped. I must be missing something obvious. File /etc/php5/apache2/php.ini relevant settings are: In my code I have: I see “About to log” on the page, but nothing in the error log. How can I fix this? Answer Restart the Web server. Until you do php.ini change…
Resize PNG image in PHP
I’m getting a no image display when resizing PNG however the following code works for JPEG. I’ve put the headers in but for some reason I’m doing something wrong for png images. Answer Last argument in imagepng($image_p, null, 100) should be between 0 and 9.