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

Reply via email to