JimmyC's profile (945 points)
About: I live for Linux. Well, not really but you know what I mean. I suppose I like it. Quite a lot.
I need strip the last few characters off a string in PHP - from the eleventh character of a word I don't want it to be any longer.
Is this possible ? Thank you.
Asked in: OtherProgramming
(2 answers)
JimmyC's response: This should help:
http://www.php.net/manual/en/function.substr-replace.php
$var = 'ABCDEFGH:/MNRPQR/';
/* These two examples replace all of $var with 'bob'. */
echo substr_replace($var, 'bob', 0) . " \n";
echo substr_replace($var, 'bob', 0, strlen($var)) . " \n";
/* Insert 'bob' right at the beginning of $var. */
echo substr_replace($var, 'bob', 0, 0) . " \n";
/* These next two replace 'MNRPQR' in $var with 'bob'. */
echo substr_replace($var, 'bob', 10, -1) . " \n";
echo substr_replace($var, 'bob', -7, -1) . " \n";
/* Delete 'MNRPQR' from $var. */
echo substr_replace($var, '', 10, -1) . " \n";
| |
| | |