Jump to content


New Members
  • Posts

  • Joined

  • Last visited

Posts posted by jyeager11

  1. To be honest, the plan was the use the "unpolished" code just to get the page to where I want it – and then look at optimizing it the way you just did – because I don't know what 100% of the needs are yet. Like a pencil outline before inking an illustration.

    Then, once I know what all my dynamic-text-replacement needs are, I can 1) Optimize the PHP file through smarter function building, and 2) Use the final updated code as a model for all future tasks of this kind.

  2. How difficult would it be to modify the original code posted (not the updated version) so that the markers are INCLUDED in the text being replaced? Currently, they are not -- only the content between them is.


    In other words, here's your first marker. Here's your second. Replace the markers and everything in-between by "this".

  3. $poststart = "<!-- Begin -->";

    $poststop = "<!-- End -->";


    $parsedpost1 = explode($poststart, $contenu);

    $parsedpost2 = explode($poststop, $parsedpost1[1]);

    $contenu = $parsedpost1[0] . $poststart . $newpost . $poststop . $parsedpost2[1];


    The above code will set 2 markers and replace whatever inside by $newpost, which is defined elsewhere in the page. But what if $newpost is so long that I'd be more comfortable storing it in a separate file? 


    How would I go about calling said file on that last line? (I'm referring to the specific syntax.)



  4. 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\">
    ","", $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. 
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.