Issue
i have file names strings like this : Admin_studies.php Studies_lang.php
and i want to replace it like this :
Admin_classes.php Classes_lang.php
which keep the case as it's and just replace the sting word
i tried something like this , but it will not keep the original chars cases
$newname = "classes";
$oldname = "studies";
$file_name = "Admin_studies.php"; //or may be $file_name = "Studies_lang.php";
echo preg_replace("/($oldname)/i","$1",$file_name );
Solution
You can set arrays for replacement templates
$newnames = ['classes', 'Classes'];
$oldnames = ['studies', 'Studies'];
$file_name = "Admin_Studies.php";
echo str_replace( $oldnames, $newnames, $file_name );
Answered By - Banzay Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.