Re: Quickie - manipulating strings

From: Date: Wed, 02 Jul 2003 11:59:20 +0000
Subject: Re: Quickie - manipulating strings
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-153693@lists.php.net to get a copy of this message
from the manual Example 1. Basic substr() usage <?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
?> If start is negative, the returned string will start at the start'th character from the end of string. Example 2. Using a negative start <?php
$rest = substr("abcdef", -1);    // returns "f"
$rest = substr("abcdef", -2);    // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d" ?> have fun Pete Matt Macleod wrote:
Hi, I need to manipulate a string to insert a space 3 characters from the right end. eg: turn 'ng23fgh' into 'ng23 fgh', or 'hfdgskfjgh23kj' into 'hfdgskfjgh2 3kj'. Any help gratefully received. Matt


« previous php.general (#153693) next »