jasonc310771 Posted February 3, 2023 Share Posted February 3, 2023 (edited) define("corrections", array("<?=" => "<?php echo ")); $newFileContents = str_replace(array_keys(corrections), corrections, $fileContents); the file contents... <? $a = "1"; ?><?=$a;?> I have taken this form https://www.designcise.com/web/tutorial/how-to-replace-words-in-a-string-based-on-a-map-in-php But do not understand why the newFileContents returned is the same as the original. Please can someone tell me what I have wrong with the code above ? EDIT i just realised i missed out the function to get content, it was only getting the file names. Edited February 3, 2023 by jasonc310771 Quote Link to comment https://forums.phpfreaks.com/topic/315875-str_replace-using-array-map-not-returning-expected-results/ Share on other sites More sharing options...
Barand Posted February 3, 2023 Share Posted February 3, 2023 Looks OK to me CODE define("corrections", array("<?=" => "<?php echo ")); $fileContents = ' <? $a = "1"; ?><?=$a;?> '; $newFileContents = str_replace(array_keys(corrections), corrections, $fileContents); echo '<pre>' . htmlentities($newFileContents) . '</pre>'; OUTPUT <? $a = "1"; ?><?php echo $a;?> Quote Link to comment https://forums.phpfreaks.com/topic/315875-str_replace-using-array-map-not-returning-expected-results/#findComment-1605346 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.