PHP页面将文本更改为常量[关闭]

I have a php site and Now i want to make it multilingual. Is there any way to parse the php pages and find text and replace it with similar php constants? I want to make an automatic script which first find all php pages inside it then find all the nodes which having text inside it and then replace it with php constatnt and at the same time add a new entry of this constant into database.

There are a lot ways. I suggest you do do it like

before: <title>Hello World</title>

after: <title><?=ts("Hello World");?></title>

Then write a function ts($source)

which cares about output the right string. This is very easy and comfortable because you can continue coding the page in English or your language and ts() is caring about everything

You should add a function like loc("Home") to everywhere, instead of typing plain text.

<li><?php echo loc("About");?></li>

If in English, loc() should return what it was given. Else it should return the translation.

$lang = "en";
$dict = Array(
    "About" => Array(
        "fr" => "Sur"
    )
);

function loc($input) {
    if ($lang == "en") {
        return $input;
    }
    return $dict[$input][$lang];
}