Hi guys. First-timer here, please be gentle. =)
I have 2 files on my server that are virtually identical, except for a script that's only located in one of them. I will soon have to create more similar files with only small changes in each. I'll spare you the long and boring explanation of why, but I now realize that it would be easier if I had a single file with all the code in it, and included that in all the other files. Only problem is, I can't modify included text for unique situations.
Or can I?
It has been brought to my attention that I can fetch the entire thing via file_get_contents(), and modify certain parts of it via str_replace(); so problem solved, right? $content = file_get_contents("code.htm"); $content = str_replace("replace this line","with this line", $content);
It works great for short strings, but what about long ones? What if I'm targeting a 100-line javascript function I want stricken on the fly, during the output? I mean I can't exactly just paste 100 lines of code between those quotation marks, can I? Could someone show me what the proper syntax to search/replace a large chunk of code on the fly would be? At first, I pictured something like this... $content = str_replace("
<script type=\"text/javascript\">
GS_googleEnableAllServices();
</script>
","", $content);
...and then realized I was straying too far from my limited PHP knowledge, because that looks wrong as hell. ;-) So here I am. Any help would be greatly appreciated. This one single hurdle has been keeping a project from advancing for a couple of days, now.