EventBuffer
PHP Manual

EventBuffer::search

(PECL event >= 1.2.6-beta)

EventBuffer::searchScans the buffer for an occurrence of a string

Description

public EventBufferPosition EventBuffer::search ( string $what [, EventBufferPosition $start = NULL [, EventBufferPosition $end = NULL ]] )

Scans the buffer for an occurrence of the string what . It returns object representing the position of the string, or NULL if the string was not found.

If the start argument is provided, it represents the position at which the search should begin; otherwise, the search is performed from the start of the string. If end argument provided, the search is performed between start and end buffer positions.

Parameters

what

String to search.

start

Instance of EventBufferPosition representing start search position.

end

Instance of EventBufferPosition representing end search position.

Return Values

Returns an instance of EventBufferPosition representing position of the first occurance of the string in the buffer, or NULL if string is not found.

Examples

Example #1 EventBuffer::search() example

<?php
// Count total occurances of 'str' in 'buf'
function count_instances($buf$str) {
    
$total 0;
    
$p = new EventBufferPosition();

    
$buf->setPosition($p0EventBuffer::PTR_SET);

    
$i 0;
    while (
1) {
        
$p $buf->search($str$p);
        if (!
$p) {
            break;
        }
        ++
$total;
        
$buf->setPosition($p1EventBuffer::PTR_ADD);
    }

    return 
$total;
}

$buf = new EventBuffer();
$buf->add("Some string within a string inside another string");
var_dump(count_instances($buf"str"));
?>

The above example will output something similar to:

int(3)

See Also


EventBuffer
PHP Manual