Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Filtering the PSR-7 body in middleware
May 16, 2016 @ 14:25:30

Rob Allen has a post to his site showing how you can filter the body content of your response in a PSR-7 compatible system via some simple middleware.

Sometimes, there's a requirement to alter the data in the Response's body after it has been created by your controller action. For example, we may want to ensure that our brand name is consistently capitalised. One way to do this is to create middleware that [uses str_ireplace to replace a string]. That's great, but what happens if the new string is shorter than the old one? For instance, suppose I want to replace all uses of "nineteen feet" with "19FT".

In his example, replacing that part of the content would result in an odd string because of how they'd be replaced in the stream. He shows how to use the in-memory handling of PHP's fopen to create a new content instance to push back into the response and back out to the waiting application.

tagged: psr7 middleware filter content strireplace stream fopen tutorial

Link: https://akrabat.com/filtering-the-psr-7-body-in-middleware/

Sameer Borate's Blog:
Read the version of a PDF in PHP
Jul 22, 2011 @ 14:54:18

Sameer Borate has a quick post to his blog today with some code that lets you read the version of a PDF document programmatically without a dependency on a PDF extension or library being installed.

The following [example] is a very short code to read the version number of a PDF document using PHP. I needed this recently during a PDF processing app developed in PHP. As Adobe uses different compression methods in various versions, it becomes necessary to be able to identify the version of the PDF under work.

The code opens the file with a fopen and parses a certain line for the major and minor version. The PDF extension for PHP can do something similar with the pdf_get_value function passing in either "major" or "minor" as the second parameter.

tagged: tutorial read version pdf file extension fopen

Link:

Total PHP:
Deleting files with PHP
Aug 06, 2008 @ 16:19:48

The Total PHP site has another introductory tutorial posted showing you how to correctly delete files in your PHP scripts.

Following our tutorials on uploading files and listing files, this tutorial will walk you through deleting files from a directory. This is done using the unlink() function.

Their example is pretty simple (as is the concept) - they show how to check to be sure that the file you want to remove isn't in use/open and then issue the unlink to remove it from the file system.

tagged: delete file upload list tutorial fopen unlink

Link:

Elizabeth Smith's Blog:
Php User Streams - why doesn't anyone use them?
May 07, 2007 @ 13:04:00

In a new post today, Elizabeth Smith takes a look at one of the lesser used (well, overall) features that PHP has to offer these days - PHP user streams.

PHP user streams are amazing - they're powerful, fun, and make things like a templating system with filters and multiple back ends quick and easy.

Here's a little "test script" that shows you how to implement contexts for your streams. What are contexts? They're resources that hold additional information. Built in php streams, such as the ftp streams, already have contexts you can set. But they're also great to use in your own user land streams.

In the test script, she shows how to open a stream to a few different resources (including passing parameters and user information), grabbing the contents of each.

tagged: user stream example path fopen user stream example path fopen

Link:

Elizabeth Smith's Blog:
Php User Streams - why doesn't anyone use them?
May 07, 2007 @ 13:04:00

In a new post today, Elizabeth Smith takes a look at one of the lesser used (well, overall) features that PHP has to offer these days - PHP user streams.

PHP user streams are amazing - they're powerful, fun, and make things like a templating system with filters and multiple back ends quick and easy.

Here's a little "test script" that shows you how to implement contexts for your streams. What are contexts? They're resources that hold additional information. Built in php streams, such as the ftp streams, already have contexts you can set. But they're also great to use in your own user land streams.

In the test script, she shows how to open a stream to a few different resources (including passing parameters and user information), grabbing the contents of each.

tagged: user stream example path fopen user stream example path fopen

Link:



Pierre-Alain Joye's Blog:
Windows fixes release for Zip, fopen(,"rb") may not be binary safe
Nov 28, 2006 @ 13:13:09

A new release of the Zip PECL package has been made according to this post on Pierre-Alain Joye's blog today. The main update in this release is to counteract a Windows bug that's interfering with binary file opens.

The issue is actually a windows bug. No matter if I give or not the "b" flag to fopen, the write operations are not binary safe. It seems to be a known issue as many projects use the same trick.

The problem comes up when PHP forces the binary mode in SAPI and CLI, making the binary writes to a file non-binary safe no matter what. Pierre is also asking for help from anyone out there with any information/bug reports/references about this issue that would yield something useful.

tagged: fopen binary safe windows force mode bug sapi cli fopen binary safe windows force mode bug sapi cli

Link:

Pierre-Alain Joye's Blog:
Windows fixes release for Zip, fopen(,"rb") may not be binary safe
Nov 28, 2006 @ 13:13:09

A new release of the Zip PECL package has been made according to this post on Pierre-Alain Joye's blog today. The main update in this release is to counteract a Windows bug that's interfering with binary file opens.

The issue is actually a windows bug. No matter if I give or not the "b" flag to fopen, the write operations are not binary safe. It seems to be a known issue as many projects use the same trick.

The problem comes up when PHP forces the binary mode in SAPI and CLI, making the binary writes to a file non-binary safe no matter what. Pierre is also asking for help from anyone out there with any information/bug reports/references about this issue that would yield something useful.

tagged: fopen binary safe windows force mode bug sapi cli fopen binary safe windows force mode bug sapi cli

Link:

ThinkPHP Blog:
Handling large files with(out) PHP
Aug 02, 2006 @ 10:47:06

On the ThinkPHP blog today, there's a quick hint about dealing with larger files both with and whithout PHP.

As one man was quoted "640K of memory should be enough for anybody" no one will need to access more than 2 GB data. What happens if you - just for scientific reasons of course - try to access larger files using your 32bit hardware and your favorite programming language PHP?

They give the example of opening a large 2 gig file with PHP and the resulting error that would pop up. They try a few differnt ways before getting down to more of a non-PHP PHP solution (yes, you read that right). They decided, instead, to create a script to work with the file chunked, using an exec() call to the unix split command to break it up.

tagged: file handling large fopen error split chunk exec file handling large fopen error split chunk exec

Link:


Trending Topics: