Last active
October 24, 2024 09:33
-
-
Save stemar/8287074 to your computer and use it in GitHub Desktop.
Revisions
-
stemar revised this gist
Dec 24, 2022 . No changes.There are no files selected for viewing
-
stemar revised this gist
May 23, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php function mb_substr_replace($string, $replacement, $start, $length=NULL) { if (is_array($string)) { $num = count($string); -
stemar renamed this gist
Feb 16, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
stemar renamed this gist
Jan 6, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
stemar revised this gist
Jan 6, 2014 . No changes.There are no files selected for viewing
-
stemar created this gist
Jan 6, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ function mb_substr_replace($string, $replacement, $start, $length=NULL) { if (is_array($string)) { $num = count($string); // $replacement $replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement); // $start if (is_array($start)) { $start = array_slice($start, 0, $num); foreach ($start as $key => $value) $start[$key] = is_int($value) ? $value : 0; } else { $start = array_pad(array($start), $num, $start); } // $length if (!isset($length)) { $length = array_fill(0, $num, 0); } elseif (is_array($length)) { $length = array_slice($length, 0, $num); foreach ($length as $key => $value) $length[$key] = isset($value) ? (is_int($value) ? $value : $num) : 0; } else { $length = array_pad(array($length), $num, $length); } // Recursive call return array_map(__FUNCTION__, $string, $replacement, $start, $length); } preg_match_all('/./us', (string)$string, $smatches); preg_match_all('/./us', (string)$replacement, $rmatches); if ($length === NULL) $length = mb_strlen($string); array_splice($smatches[0], $start, $length, $rmatches[0]); return join($smatches[0]); }