I was working on some code the other evening and found myself needing a version of PHP’s bcmod function in JavaScript. It wasn’t already available at jsphp.co so I implemented it and posted about it to the ProgClub programming list.
Tag Archives: php
MemberNet PHP tests now have submenu
I’ve been working on my PHP tests system on my MemberNet site.
As you can see if you check out one of the tests, for example the phpinfo test, there is now a submenu that has links for the HTML source, the PHP source, the W3C HTML validator and the W3C CSS validator.
PHP str_pad
Found myself using the PHP function str_pad today to format a hex string as a six digit HTML/CSS colour code.
e.g.:
$code = str_pad( dechex( $rgb ), 6, '0', STR_PAD_LEFT );
The str_pad function is implemented in JavaScript at jsphp.co.
PHP ini file allow_url_include configuration option
Today I enabled the allow_url_include configuration option in PHP on Apache on ProgClub MemberNet. This allows me to include a source file directly from svn, e.g.:
require_once( 'https://www.progclub.org/svn/pcrepo/slib/trunk/src/uri.php' );
PHP get_called_class function
I learned about the PHP get_called_class function today. Basically it returns the name of the class that the function that’s running is defined in. Handy for figuring out which class a static method is running in. Compare with get_class.
Reading a file in PHP
The file function parses a text file into an array, and the file_get_contents function returns a text file as a string.
PHP ini file user_agent configuration option
Today I discovered the user_agent php.ini configuration option. Basically it allows you to specify the user agent PHP uses when it sends HTTP requests for files. I was screen scraping some data from Wikipedia (processing URI schemes) and it was replying with a 403 error, presumably because they’ve banned the default PHP user agent. Anyway I just changed my user agent to a copy of my one from Firefox and things started working. Pretty handy option!
PHP heredoc syntax
Today I used the PHP for the first time.
$data = <<<EOF my data EOF; echo $data;
PHP error_log
File upload error – unable to create a temporary file in Unknown on line 0
I was working with phpMyAdmin and I got the following error:
File upload error - unable to create a temporary file in Unknown on line 0
The problem was that the upload_tmp_dir setting in my php.ini file was specified twice. Once up the top of the file where I was editing it, and then later in the file where I didn’t see it. So the setting I wanted wasn’t being applied. If you get this error double check you’ve only got one setting for upload_tmp_dir.