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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php