Re: I need ob_write($string, $start, $length)
| From: | Curt Zirzow | Date: | Tue, 03 Aug 2004 06:01:39 +0000 |
| Subject: | Re: I need ob_write($string, $start, $length) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-192522@lists.php.net to get a copy of this message | ||
* Thus wrote jtl_phpdotnet@spamex.com:
> The guys in the internals list sent me to this forum.
>
> I am trying to write some serious parsing software in PHP. I
> need to use plain, vanilla PHP and no add-on modules, because I
> need to be able to distribute to people who don't have sufficient
> privileges.
>
> In the process of parsing I create a new document composed of
> concatenated pieces of the original document. I am efficiently
> catting the new document using output buffer, but when I have to
> copy non-contiguous pieces form the original document, I am
> forced to create substrings, as in:
>
> echo substr($originalDoc, $startOfSnippet, $snippetLength)
>
> My documents are potentially large with possibly thousands of
> such substrings. I know from writing Java parsers for
> high-throughput servers that object creation, and in particular
> string creation, is the greatest source of degraded performance.
>
> I'd like to copy the contents of a substring directly to the
> output buffer without creating an intermediate object, as in:
>
> ob_write($string, $start, $length)
>
> I can find no such function and could envision no other way to do
> this at present.
>
I'm not entirely clear at what your trying to do but perhaps you
want something like this:
function print_substr_direct($string, $start, $len) {
static $fp = null;
if ($fp === null ) {
// Open a connection directly to the output
$fp = fopen('php://stdout', 'r');
}
if ($fp) {
fputs($fp, substr($string, $start, $len));
}
}
Curt
--
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about. No, sir. Our model is the trapezoid!