mirror of
https://github.com/php/doc-it.git
synced 2026-03-29 11:02:22 +02:00
git-svn-id: https://svn.php.net/repository/phpdoc/it/trunk@327389 c90b9560-bf6c-de11-be94-00142212c4b1
125 lines
3.7 KiB
XML
125 lines
3.7 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- EN-Revision: n/a Maintainer: darvina Status: ready -->
|
|
<!-- splitted from ./en/functions/strings.xml, last change in rev 1.2 -->
|
|
<refentry xml:id="function.strtok" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>strtok</refname>
|
|
<refpurpose>Suddivide una stringa in token</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descrizione</title>
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>strtok</methodname>
|
|
<methodparam><type>string</type><parameter>str</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>token</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>strtok</function> suddivide la stringa(<parameter>str</parameter>)
|
|
in piccole stringhe (tokens), in cui ciascun token è delimitato dal
|
|
carattere indicato in <parameter>token</parameter>.
|
|
Perciò, se si ha la stringa "This is an example string" la si può
|
|
dividere nelle singole parole utilizzando come separatore
|
|
lo spazio.
|
|
<example>
|
|
<title>Esempio di uso di <function>strtok</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$string = "This is\tan example\nstring";
|
|
/* Use tab and newline as tokenizing characters as well */
|
|
$tok = strtok($string, " \n\t");
|
|
while ($tok !== false) {
|
|
echo "Word=$tok<br />";
|
|
$tok = strtok(" \n\t");
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Soltanto la prima chiamata a <function>strtok</function> utilizza il parametro stringa.
|
|
Ogni chiamata successiva richiede solo il carattere da utilizzare, poiché
|
|
la funzione tiene traccia di dove è arrivata nella stringa corrente. Per ripartire da capo
|
|
o iniziare con una nuova stringa ri-chiamare <function>strtok</function>
|
|
con il parametro stringa. Nota: si possono mettere più caratteri
|
|
come separatori di stringhe. Il testo iniziale verrà suddiviso
|
|
quando viene trovato uno qualsiasi di questi caratteri.
|
|
Attenzione che soltanto la prima chiamata di strtok userà l'argomento stringa.
|
|
</para>
|
|
<para>
|
|
Il comportamento su segmenti vuoti è cambiato dal PHP 4.1.0. La vecchia
|
|
versione restituiva una stringa vuota, mentre la nuova, più correttamente,
|
|
salta quella parte di stringa:
|
|
<example>
|
|
<title>Vecchio comportamento di <function>strtok</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$first_token = strtok('/something', '/');
|
|
$second_token = strtok('/');
|
|
var_dump($first_token, $second_token);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Output:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
string(0) ""
|
|
string(9) "something"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<example>
|
|
<title>Nuovo comportamento di <function>strtok</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$first_token = strtok('/something', '/');
|
|
$second_token = strtok('/');
|
|
var_dump($first_token, $second_token);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Output:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
string(9) "something"
|
|
bool(false)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
&return.falseproblem;
|
|
<para>
|
|
Vedere anche: <function>split</function> e
|
|
<function>explode</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|