mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
Added examples for accesing the last char of a string (I always forget!)
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@177566 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
68fc1bda46
commit
de36e70579
1 changed files with 12 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/strings.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.substr">
|
||||
<refnamediv>
|
||||
|
@ -33,15 +33,19 @@
|
|||
<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"
|
||||
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
|
||||
|
||||
// Accessing via curly braces is another option
|
||||
// Accessing single characters in a string
|
||||
// can also be achived using "curly braces"
|
||||
$string = 'abcdef';
|
||||
echo $string{0}; // returns a
|
||||
echo $string{3}; // returns d
|
||||
echo $string{0}; // a
|
||||
echo $string{3}; // d
|
||||
echo $string{strlen($string)-1} // f
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
Loading…
Reference in a new issue