dunno how much slower it'd be, but it might look better. You could convert
the strings to an array, use array_splice(), and then convert back to a
string.

-----Original Message-----
From: Justin French [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 19, 2002 3:39 PM
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')


This is what I think would work (untested), looking for pointers,
optimisation, or a better approach:

<?
$str = 'abcdefghijklmnop';
$strip_start = 4;
$strip_end = 7;
$filler = '4567';

$pre = substr($str,0,$strip_start-1);            // abc
$post = substr($str,$strip_end+1,strlen($str));  // hijklmnop

$str = $pre.$filler.$post;  //abc4567hijklmnop
?>

Thanks,

Justin French


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to