how to write in a text file before a given word

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kindermaxiz@yahoo.com

    how to write in a text file before a given word

    I have a english.php with a list of variable containing the
    translation. It kinda looks like this:

    <?php

    $hello = "hello";
    $button_value = "submit";

    ?>

    I need a function that write text such as "$new_translati on =
    "translatio n";" on the english.php file on the line before the "?>"
    tag, how can I do this?

    thanx in advance

    Pat
  • Jasper Bryant-Greene

    #2
    Re: how to write in a text file before a given word

    kindermaxiz@yah oo.com wrote:
    [color=blue]
    > I have a english.php with a list of variable containing the
    > translation. It kinda looks like this:
    >
    > <?php
    >
    > $hello = "hello";
    > $button_value = "submit";
    >
    > ?>
    >
    > I need a function that write text such as "$new_translati on =
    > "translatio n";" on the english.php file on the line before the "?>"
    > tag, how can I do this?
    >
    > thanx in advance
    >
    > Pat[/color]

    The way I understand it, you want a PHP script to modify your PHP
    script. If this is not the case, please let me know.

    You could do that like this:

    $file = file_get_conten ts('/path/to/english.php');
    $file = str_replace('?> ',"$new_transla tion=\"translat ion\";\n?>",$fi le);
    $fp = fopen('/path/to/english.php','w ');
    fwrite($fp,$fil e);
    fclose($fp);

    --
    Jasper Bryant-Greene
    Cabbage Promotions

    Comment

    Working...