<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Scans the buffer for an occurrence of a string</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="eventbuffer.readline.html">EventBuffer::readLine</a></div> <div class="next" style="text-align: right; float: right;"><a href="eventbuffer.searcheol.html">EventBuffer::searchEol</a></div> <div class="up"><a href="class.eventbuffer.html">EventBuffer</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="eventbuffer.search" class="refentry"> <div class="refnamediv"> <h1 class="refname">EventBuffer::search</h1> <p class="verinfo">(PECL event >= 1.2.6-beta)</p><p class="refpurpose"><span class="refname">EventBuffer::search</span> — <span class="dc-title">Scans the buffer for an occurrence of a string</span></p> </div> <div class="refsect1 description" id="refsect1-eventbuffer.search-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>EventBuffer::search</strong></span> ( <span class="methodparam"> <span class="type">string</span> <code class="parameter">$what</code> </span> [, <span class="methodparam"> <span class="type">int</span> <code class="parameter">$start</code> <span class="initializer"> = -1</span> </span> [, <span class="methodparam"> <span class="type">int</span> <code class="parameter">$end</code> <span class="initializer"> = -1</span> </span> ]] )</div> <p class="para rdfs-comment"> Scans the buffer for an occurrence of the string <em><code class="parameter">what</code></em> . It returns numeric position of the string, or <strong><code>FALSE</code></strong> if the string was not found. </p> <p class="para"> If the <em><code class="parameter">start</code></em> argument is provided, it points to the position at which the search should begin; otherwise, the search is performed from the start of the string. If <em><code class="parameter">end</code></em> argument provided, the search is performed between start and end buffer positions. </p> </div> <div class="refsect1 parameters" id="refsect1-eventbuffer.search-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <span class="term"> <em><code class="parameter">what</code></em> </span> <dd> <p class="para"> String to search. </p> </dd> </dt> <dt> <span class="term"> <em><code class="parameter">start</code></em> </span> <dd> <p class="para"> Start search position. </p> </dd> </dt> <dt> <span class="term"> <em><code class="parameter">end</code></em> </span> <dd> <p class="para"> End search position. </p> </dd> </dt> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-eventbuffer.search-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns numeric position of the first occurance of the string in the buffer, or <strong><code>FALSE</code></strong> if string is not found. </p> <div class="warning"><strong class="warning">Warning</strong><p class="simpara">This function may return Boolean <strong><code>FALSE</code></strong>, but may also return a non-Boolean value which evaluates to <strong><code>FALSE</code></strong>. Please read the section on <a href="language.types.boolean.html" class="link">Booleans</a> for more information. Use <a href="language.operators.comparison.html" class="link">the === operator</a> for testing the return value of this function.</p></div> </div> <div class="refsect1 examples" id="refsect1-eventbuffer.search-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-4250"> <p><strong>Example #1 <span class="function"><strong>EventBuffer::search()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Count total occurances of 'str' in 'buf'<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">count_instances</span><span style="color: #007700">(</span><span style="color: #0000BB">$buf</span><span style="color: #007700">, </span><span style="color: #0000BB">$str</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$total </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$p </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /><br /> while (</span><span style="color: #0000BB">1</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$p </span><span style="color: #007700">= </span><span style="color: #0000BB">$buf</span><span style="color: #007700">-></span><span style="color: #0000BB">search</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </span><span style="color: #0000BB">$p</span><span style="color: #007700">);<br /> if (</span><span style="color: #0000BB">$p </span><span style="color: #007700">=== </span><span style="color: #0000BB">FALSE</span><span style="color: #007700">) {<br /> break;<br /> }<br /> ++</span><span style="color: #0000BB">$total</span><span style="color: #007700">;<br /> ++</span><span style="color: #0000BB">$p</span><span style="color: #007700">;<br /> }<br /><br /> return </span><span style="color: #0000BB">$total</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$buf </span><span style="color: #007700">= new </span><span style="color: #0000BB">EventBuffer</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$buf</span><span style="color: #007700">-></span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #DD0000">"Some string within a string inside another string"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">count_instances</span><span style="color: #007700">(</span><span style="color: #0000BB">$buf</span><span style="color: #007700">, </span><span style="color: #DD0000">"str"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> int(3) </pre></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-eventbuffer.search-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="eventbuffer.searcheol.html" class="methodname" rel="rdfs-seeAlso">EventBuffer::searchEol()</a> - Scans the buffer for an occurrence of an end of line</span> </li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="eventbuffer.readline.html">EventBuffer::readLine</a></div> <div class="next" style="text-align: right; float: right;"><a href="eventbuffer.searcheol.html">EventBuffer::searchEol</a></div> <div class="up"><a href="class.eventbuffer.html">EventBuffer</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>