Created
October 18, 2020 19:36
-
-
Save Hillzacky/e2ffd26653094c9dbbdc04c973a37305 to your computer and use it in GitHub Desktop.
str_replace multiple pattern code string in php bulk replace string
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 | |
function wordTruth ($text,$args=[]){ | |
foreach($args as $k => $v){ | |
$key[] = $k; | |
$value[]= $v; | |
} | |
return str_replace($key,$value,$text); | |
} | |
$name = "Akunk"; | |
$gender = "gadis"; | |
$text = "Hai [gender] kamu istimewa, kenalkan nama saya [nama]."; | |
print_r( wordTruth($text,["[nama]"=>$name,"[gender]"=>$gender]) ); | |
/** | |
Output: | |
Hai gadis kamu istimewa, kenalkan nama saya Akunk. | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment