1
0
mirror of https://github.com/php/doc-it.git synced 2026-03-24 23:52:12 +01:00
Files
Richard Quadling 2769b12f1b Reencode XML to UTF-8
git-svn-id: https://svn.php.net/repository/phpdoc/it/trunk@314558 c90b9560-bf6c-de11-be94-00142212c4b1
2011-08-08 16:37:53 +00:00

129 lines
4.5 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.substr" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>substr</refname>
<refpurpose>Restituisce parte di una stringa</refpurpose>
</refnamediv>
<refsect1>
<title>Descrizione</title>
<methodsynopsis>
<type>string</type><methodname>substr</methodname>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
<methodparam><type>int</type><parameter>start</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam>
</methodsynopsis>
<para>
La funzione <function>substr</function> restituisce la porzione di <parameter>string</parameter>
indicata dai parametri <parameter>start</parameter> e
<parameter>length</parameter>.
</para>
<para>
Se <parameter>start</parameter> non è negativo, la stringa restituita
inizierà dalla posizione <parameter>start</parameter> di
<parameter>string</parameter>, partendo da zero. Ad esempio,
nella stringa '<literal>abcdef</literal>', il carattere alla posizione
<literal>0</literal> è '<literal>a</literal>', il carattere alla
posizione <literal>2</literal> è
'<literal>c</literal>', e così via.
</para>
<example>
<title>Esempi di base di <function>substr</function></title>
<programlisting role="php">
<![CDATA[
<?php
echo substr('abcdef', 1); // bcdef
echo substr('abcdef', 1, 3); // bcd
echo substr('abcdef', 0, 4); // abcd
echo substr('abcdef', 0, 8); // abcdef
echo substr('abcdef', -1, 1); // f
// Accedere al singolo carattere
// tramite le parentesi graffe è un'altra possibilità
$string = 'abcdef';
echo $string{0}; // a
echo $string{3}; // d
echo $string{strlen($string)-1}; // f
?>
]]>
</programlisting>
</example>
<para>
Se <parameter>start</parameter> è negativo, la stringa restituita
inizierà dal carattere <parameter>start</parameter>
dalla fine di <parameter>string</parameter>.
</para>
<example>
<title>Utilizzo di valori negativi di <parameter>start</parameter></title>
<programlisting role="php">
<![CDATA[
<?php
$rest = substr("abcdef", -1); // restituisce "f"
$rest = substr("abcdef", -2); // restituisce "ef"
$rest = substr("abcdef", -3, 1); // restituisce "d"
?>
]]>
</programlisting>
</example>
<para>
Se <parameter>length</parameter> è indicato ed è positivo, la stringa
restituita conterrà almeno <parameter>length</parameter> caratteri
partendo da <parameter>start</parameter> (in base alla lunghezza di
<parameter>string</parameter>). Se <parameter>string</parameter> è minore
o uguale a <parameter>start</parameter>, la funzione restituisce
&false;
</para>
<para>
Se <parameter>length</parameter> è indicato ed è negativo, allora saranno omessi
<parameter>length</parameter> caratteri dalla fine di <parameter>string</parameter>
(dopo avere calcolato la posizione iniziale, nel caso in cui
<parameter>start</parameter> sia negativo). Se
<parameter>start</parameter> indica una posizione successiva a questo troncamento,
la funzione restituirà una stringa vuota.
</para>
<example>
<title>Utilizzo di valori negativi per <parameter>length</parameter></title>
<programlisting role="php">
<![CDATA[
<?php
$rest = substr("abcdef", 0, -1); // returns "abcde"
$rest = substr("abcdef", 2, -1); // returns "cde"
$rest = substr("abcdef", 4, -4); // returns ""
$rest = substr("abcdef", -3, -1); // returns "de"
?>
]]>
</programlisting>
</example>
<para>
Vedere anche <function>strrchr</function>,
<function>substr_replace</function>,
<function>ereg</function>,
<function>trim</function>,
<function>mb_substr</function> e
<function>wordwrap</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
-->