Skip to content

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:

PHP return type

Is it possible to define the return type like this? public static function bool Test($value) { return $value; //this value will be bool }

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

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.