1

スクリプト内の$emailすべてを置き換える必要がある変数があります。<!--email-->

誰かがそれを行うための最良の方法を教えてくれますか?現在私はやっています:

$email = $_SESSION["email"];
str_replace("<!--email-->",$email,"<!--email-->") 
4

2 に答える 2

1
$email = $_SESSION["email"];
$filename = 'script.php';
$script = str_replace("<!--email-->",$email,file_get_contents($filename));

ファイル内のすべてが変更され、保存するかエコーするだけです

于 2012-08-01T01:42:43.167 に答える
0

これは基本的にすべての変数を取得<!--tag-->し、適切な名前の変数に置き換える4 ライナーです。

$string = "string or output from file_get_contents()";

preg_match_all("/<!--([A-z0-9_]+)-->/", $string, $matches);

foreach($matches[1] as $match){
$string = preg_replace("/<!--([$match]+)-->/i", ${$match}, $string);
}

echo $string;
于 2012-08-01T02:25:25.297 に答える