PHP supports the "data: stream wrapper" natively, so you don't have to do ugly string manipulation to get, for example, the data from a string such as data://text/plain;base64,SSBsb3ZlIFBIUAo=. Instead, you can do this:

$string = 'data://text/plain;base64,SSBsb3ZlIFBIUAo=';
$source = fopen($string, 'r');
$destination = fopen('myfile.txt', 'w');

stream_copy_to_stream($source, $destination);

fclose($source);
fclose($destination);
Read more

Apparently, PHP can work just fine without loading a php.ini configuration file. I have no idea where it gets its default configuration from (for example, a value of 128M for memory_limit), but luckily phpinfo() will tell you where it's looking for a php.ini (search for "Configuration File" in its output), so you can just add the file in that path and it will get picked up.

Read more

There's a simple algorithm that uses the Bayes theorem that can be used to classify documents, using their text tokenized into individual words, into categories (e.g. tags on a website). The classifier needs to be trained with existing data, and then it will return which categories a new document probably belongs to.

Read more
Subscribe to PHP