<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.imap.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.imap-search.php',
    1 => 'imap_search',
    2 => 'This function returns an array of messages matching the given search criteria',
  ),
  'up' => 
  array (
    0 => 'ref.imap.php',
    1 => 'IMAP Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.imap-scanmailbox.php',
    1 => 'imap_scanmailbox',
  ),
  'next' => 
  array (
    0 => 'function.imap-set-quota.php',
    1 => 'imap_set_quota',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/imap/functions/imap-search.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.imap-search" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imap_search</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imap_search</span> &mdash; <span class="dc-title">This function returns an array of messages matching the given search criteria</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imap-search-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imap_search</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.imap-connection.php" class="type IMAP\Connection">IMAP\Connection</a></span> <code class="parameter">$imap</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$criteria</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code><a href="imap.constants.php#constant.se-free">SE_FREE</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$charset</code><span class="initializer"> = &quot;&quot;</span></span><br>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   This function performs a search on the mailbox currently opened
   in the given <abbr title="Internet Message Access Protocol">IMAP</abbr> stream. 
  </p>
  <p class="para">
   For example, to match all unanswered messages sent by Mom, you&#039;d
   use: &quot;UNANSWERED FROM mom&quot;. Searches appear to be case
   insensitive. This list of criteria is from a reading of the UW
   c-client source code and may be incomplete or
   inaccurate (see also <a href="https://datatracker.ietf.org/doc/html/rfc1176" class="link external">&raquo;&nbsp;RFC1176</a>, 
   section &quot;tag SEARCH search_criteria&quot;).
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imap-search-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    <dt>
<code class="parameter">imap</code></dt><dd><p class="para">An <span class="classname"><a href="class.imap-connection.php" class="classname">IMAP\Connection</a></span> instance.</p></dd>
    
     <dt><code class="parameter">criteria</code></dt>
     <dd>
      <p class="para">
       A string, delimited by spaces, in which the following keywords are
       allowed. Any multi-word arguments (e.g.
       <code class="literal">FROM &quot;joey smith&quot;</code>) must be quoted. Results will match
       all <code class="parameter">criteria</code> entries.
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          ALL - return all messages matching the rest of the criteria
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          ANSWERED - match messages with the \\ANSWERED flag set
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          BCC &quot;string&quot; - match messages with &quot;string&quot; in the Bcc: field
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          BEFORE &quot;date&quot; - match messages with Date: before &quot;date&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          BODY &quot;string&quot; - match messages with &quot;string&quot; in the body of the message
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          CC &quot;string&quot; - match messages with &quot;string&quot; in the Cc: field
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          DELETED - match deleted messages
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          FLAGGED - match messages with the \\FLAGGED (sometimes
          referred to as Important or Urgent) flag set
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          FROM &quot;string&quot; - match messages with &quot;string&quot; in the From: field
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          KEYWORD &quot;string&quot; - match messages with &quot;string&quot; as a keyword
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          NEW - match new messages
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          OLD - match old messages
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          ON &quot;date&quot; - match messages with Date: matching &quot;date&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          RECENT - match messages with the \\RECENT flag set
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          SEEN - match messages that have been read (the \\SEEN flag is set)
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          SINCE &quot;date&quot; - match messages with Date: after &quot;date&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          SUBJECT &quot;string&quot; - match messages with &quot;string&quot; in the Subject:
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          TEXT &quot;string&quot; - match messages with text &quot;string&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          TO &quot;string&quot; - match messages with &quot;string&quot; in the To:
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNANSWERED - match messages that have not been answered
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNDELETED - match messages that are not deleted
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNFLAGGED - match messages that are not flagged
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNKEYWORD &quot;string&quot; - match messages that do not have the
          keyword &quot;string&quot;
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          UNSEEN - match messages which have not been read yet
         </span>
        </li>
       </ul>
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       Valid values for <code class="parameter">flags</code> are 
       <strong><code><a href="imap.constants.php#constant.se-uid">SE_UID</a></code></strong>, which causes the returned array to
       contain UIDs instead of messages sequence numbers.
      </p>
     </dd>
    
    
     <dt><code class="parameter">charset</code></dt>
     <dd>
      <p class="para">
       MIME character set to use when searching strings.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imap-search-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns an array of message numbers or UIDs.
  </p>
  <p class="para">
   Return <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if it does not understand the search
   <code class="parameter">criteria</code> or no messages have been found.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.imap-search-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  The <code class="parameter">imap</code> parameter expects an <span class="classname"><a href="class.imap-connection.php" class="classname">IMAP\Connection</a></span>
  instance now; previously, a valid <code class="literal">imap</code> <a href="language.types.resource.php" class="link">resource</a> was expected.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.imap-search-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="imap-search.examples">
   <p><strong>Example #1 <span class="function"><strong>imap_search()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$imap   </span><span style="color: #007700">= </span><span style="color: #0000BB">imap_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'{imap.example.com:993/imap/ssl}INBOX'</span><span style="color: #007700">, </span><span style="color: #DD0000">'foo@example.com'</span><span style="color: #007700">, </span><span style="color: #DD0000">'pass123'</span><span style="color: #007700">, </span><span style="color: #0000BB">OP_READONLY</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$some   </span><span style="color: #007700">= </span><span style="color: #0000BB">imap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$imap</span><span style="color: #007700">, </span><span style="color: #DD0000">'SUBJECT "HOWTO be Awesome" SINCE "8 August 2008"'</span><span style="color: #007700">, </span><span style="color: #0000BB">SE_UID</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$msgnos </span><span style="color: #007700">= </span><span style="color: #0000BB">imap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$imap</span><span style="color: #007700">, </span><span style="color: #DD0000">'ALL'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$uids   </span><span style="color: #007700">= </span><span style="color: #0000BB">imap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$imap</span><span style="color: #007700">, </span><span style="color: #DD0000">'ALL'</span><span style="color: #007700">, </span><span style="color: #0000BB">SE_UID</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$some</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$msgnos</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$uids</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [0] =&gt; 4
    [1] =&gt; 6
    [2] =&gt; 11
)
Array
(
    [0] =&gt; 1
    [1] =&gt; 2
    [2] =&gt; 3
    [3] =&gt; 4
    [4] =&gt; 5
    [5] =&gt; 6
)
Array
(
    [0] =&gt; 1
    [1] =&gt; 4
    [2] =&gt; 6
    [3] =&gt; 8
    [4] =&gt; 11
    [5] =&gt; 12
)</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.imap-search-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.imap-listscan.php" class="function" rel="rdfs-seeAlso">imap_listscan()</a> - Returns the list of mailboxes that matches the given text</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>