<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.strpos.php',
    1 => 'strpos',
    2 => 'Trova la posizione della prima occorrenza di una stringa',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.strpbrk.php',
    1 => 'strpbrk',
  ),
  'next' => 
  array (
    0 => 'function.strrchr.php',
    1 => 'strrchr',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'reference/strings/functions/strpos.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.strpos" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">strpos</h1>
    <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">strpos</span> &mdash; <span class="dc-title">
     Trova la posizione della prima occorrenza di una stringa
    </span></p>

   </div>
   <div class="refsect1 unknown-1420" id="refsect1-function.strpos-unknown-1420">
    <h3 class="title">Descrizione</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>strpos</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$haystack</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$needle</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$offset</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

    <p class="para rdfs-comment">
     Restituisce la posizione numerica della prima occorrenza di
     <code class="parameter">needle</code> nella stringa
     <code class="parameter">haystack</code>. Differentemente rispetto a 
     <span class="function"><a href="function.strrpos.php" class="function">strrpos()</a></span>, questa funzione considera tutta la stringa
     <code class="parameter">needle</code>, e, quindi, cercherà tutta
     la stringa.
    </p>
    <p class="para">
     Se <code class="parameter">needle</code> non viene trovato
     <span class="function"><strong>strpos()</strong></span> restituirà <span class="type"><a href="language.types.boolean.php" class="type boolean">boolean</a></span> <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
    </p>
    
    <div class="warning"><strong class="warning">Avviso</strong><p class="simpara">Questa funzione può
restituire il Booleano <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, ma può anche restituire un valore non-Booleano valutato
come <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. Fare riferimento alla sezione <a href="language.types.boolean.php" class="link">Booleans</a> per maggiori 
informazioni. Usare <a href="language.operators.comparison.php" class="link">l&#039;operatore ===
</a> per controllare il valore restituito da questa 
funzione.</p></div>
    <blockquote class="note"><p><strong class="note">Nota</strong>: <span class="simpara">Questa funzione è
 binary-safe (gestisce correttamente i file binari)</span></p></blockquote>
    <p class="para">
     <div class="example" id="example-1">
     <p><strong>Example #1 Esempio di uso di <span class="function"><strong>strpos()</strong></span></strong></p>
      <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$mystring </span><span style="color: #007700">= </span><span style="color: #DD0000">'abc'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$findme   </span><span style="color: #007700">= </span><span style="color: #DD0000">'a'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$pos </span><span style="color: #007700">= </span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring</span><span style="color: #007700">, </span><span style="color: #0000BB">$findme</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Notate l'uso di ===.  Il == non avrebbe risposto come atteso<br />// poiché la posizione di 'a' è nel primo carattere.<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$pos </span><span style="color: #007700">=== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"The string '</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">' was not found in the string '</span><span style="color: #0000BB">$mystring</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">"The string '</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">' was found in the string '</span><span style="color: #0000BB">$mystring</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br />    echo </span><span style="color: #DD0000">" and exists at position </span><span style="color: #0000BB">$pos</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// Ricerca di un carattere ignorando qualsiasi cosa prima di offset<br /></span><span style="color: #0000BB">$newstring </span><span style="color: #007700">= </span><span style="color: #DD0000">'abcdef abcdef'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$pos </span><span style="color: #007700">= </span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$newstring</span><span style="color: #007700">, </span><span style="color: #DD0000">'a'</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">); </span><span style="color: #FF8000">// $pos = 7, not 0<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
      </div>

     </div>
    </p>
    <p class="para">
     Se <code class="parameter">needle</code> non è una stringa, viene convertito
     in un intero e utilizzato come valore ordinale di un carattere.
    </p>
    <p class="para">
     Il parametro opzionale <code class="parameter">offset</code> permette di indicare
     da quale carattere in <code class="parameter">haystack</code> 
     iniziare la ricerca. La posizione restituita è, comunque, relativa 
     all&#039;inizio di <code class="parameter">haystack</code>.
    </p>
    <p class="para">
     Vedere anche <span class="function"><a href="function.strrpos.php" class="function">strrpos()</a></span>, 
     <span class="function"><a href="function.stripos.php" class="function">stripos()</a></span>,
     <span class="function"><a href="function.strripos.php" class="function">strripos()</a></span>,
     <span class="function"><a href="function.strrchr.php" class="function">strrchr()</a></span>, 
     <span class="function"><a href="function.substr.php" class="function">substr()</a></span>,
     <span class="function"><a href="function.stristr.php" class="function">stristr()</a></span> e
     <span class="function"><a href="function.strstr.php" class="function">strstr()</a></span>.
    </p>
   </div>

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