Solution: 1
You can replace a specific part of a delimited string using explode(), strstr(), and implode():
$new_value = "My New String";
$haystack = "2548: First Result|2547: Old Value|2550: Third Result|2551: Fourth Result";
$array = explode("|", $haystack);
$new_array = [];
foreach ($array as $item) {
$new_array[] = (strstr($item, '2547:')) ? "2547: " . $new_value : $item;
}
$result = implode("|", $new_array);
print_r($result);
/*
Output:
2548: First Result|2547: My New String|2550: Third Result|2551: Fourth Result
*/
✅ This approach scans each segment, replaces the one starting with 2547:, and then reconstructs the string.