RE: [PHP] best way to delete char# 4-7 from a string?
| From: | joakim dot andersson at cybercom dot se | Date: | Fri, 19 Jul 2002 08:28:47 +0000 |
| Subject: | RE: [PHP] best way to delete char# 4-7 from a string? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-108463@lists.php.net to get a copy of this message | ||
> From: Justin French [mailto:justin@indent.com.au]
> Sent: Friday, July 19, 2002 7:39 AM
> To: php
> Subject: [PHP] best way to delete char# 4-7 from a string?
>
>
> Hi,
>
> Let's say I have the following string:
>
> $str = 'abcdefghijklmnop';
>
> ...and I want to strip out char #'s 4 through to 7 (d,e,f,g)
>
> $strip_start = 4;
> $strip_end = 7;
>
> ($str would now be 'abchijklmnop';)
>
> THEN I want to plug a new string $filler at position 4
>
> $filler = '4567';
>
> ($str would now be 'abc4567hijklmnop')
Hi,
substr_replace() does exactly what you want.
$newstring = substr_replace($str, "4567", 4, 4);
Regards
Joakim Andersson