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.
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.
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' );
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.
The file function parses a text file into an array, and the file_get_contents function returns a text file as a string.
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!
Today I used the PHP for the first time.
$data = <<<EOF my data EOF; echo $data;
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.
On my list of things to do (at a rather low priority) is learning more about how to convert html to text in php.
Today I learned about the php_ini_loaded_file function. It returns the path to the php.ini file if one is loaded. This function is implemented in JavaScript at jsphp.co, but the implementation isn’t very interesting.