+ Accessing as $string{3} works too.

+ Added <?php ?> to all examples.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@88108 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2002-07-08 20:49:45 +00:00
parent b452ebaf85
commit 19e072b2af

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- $Revision: 1.3 $ -->
<!-- splitted from ./en/functions/strings.xml, last change in rev 1.2 -->
<refentry id="function.substr">
<refnamediv>
@ -32,10 +32,17 @@
<title>Basic <function>substr</function> usage</title>
<programlisting role="php">
<![CDATA[
<?php
$rest = substr("abcdef", 1); // returns "bcdef"
$rest = substr("abcdef", 1, 3); // returns "bcd"
$rest = substr("abcdef", 0, 4); // returns "abcd"
$rest = substr("abcdef", 0, 8); // returns "abcdef"
// Accessing via curly braces is another option
$string = 'abcdef';
echo $string{0}; // returns a
echo $string{3}; // returns d
?>
]]>
</programlisting>
</example>
@ -47,9 +54,11 @@ $rest = substr("abcdef", 0, 8); // returns "abcdef"
<title>Using a negative <parameter>start</parameter></title>
<programlisting role="php">
<![CDATA[
<?php
$rest = substr("abcdef", -1); // returns "f"
$rest = substr("abcdef", -2); // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"
?>
]]>
</programlisting>
</example>
@ -73,10 +82,12 @@ $rest = substr("abcdef", -3, 1); // returns "d"
<title>Using a negative <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>