Last active
August 21, 2020 14:43
-
-
Save mouadziani/6f0430fe3abbe1439d27b3b5b9aa3c85 to your computer and use it in GitHub Desktop.
This file contains 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 characters
<?php | |
// Replace the first occurence of string | |
function str_replace_first($from, $to, $content) { | |
$from = '/'.preg_quote($from, '/').'/'; | |
return preg_replace($from, $to, $content, 1); | |
} | |
echo str_replace_first('ADT', 'CHD', 'abcdefqsdfhsgqhd(ADTfhqsdf (ADT)(INF) abcdef abcdef'); | |
// abcdefqsdfhsgqhd(CHDfhqsdf (ADT)(INF) abcdef abcdef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment