值得注意的是,當起始位置和長度皆為負數,且長度小於或等於起始位置時,長度的效果將被設為 0。
<?php
substr_replace('eggs','x',-1,-1); substr_replace('eggs','x',-1,-2); substr_replace('eggs','x',-1,-2); ?>
與以下相同
<?php
substr_replace('eggs','x',-1,0); ?>
<?php
substr_replace('huevos','x',-2,-2); substr_replace('huevos','x',-2,-3); substr_replace('huevos','x',-2,-3); ?>
與以下相同
<?php
substr_replace('huevos','x',-2,0); ?>
另一個注意事項是,如果長度為負數且起始偏移量與長度相同的位置,則長度(再次)將具有如同設定為 0 的效果。(當然,如手冊中所述,當長度為負數時,它實際上代表它之前的位置)
<?php
substr_replace('abcd', 'x', 0, -4); ?>
與以下相同
<?php
substr_replace('abcd','x',0,0); ?>
<?php
substr_replace('abcd', 'x', 1, -3); ?>
與以下相同
<?php
substr_replace('abcd', 'x', 1, 0); ?>