douben7493
2014-10-14 17:31
浏览 67
已采纳

在没有<?php?>的情况下用HTML中的值替换变量

Here is the situation. I have 2 files

content.php

<?php $my_var = "this is a variable"; ?>
<h1> php{my_var} </h1>

index.php

<?php include "content.php" ?>

The result should be:

<h1>this is a variable</h1>

I know how to work with preg_replace_callback. But I don't know how can I change php{my_var} with the value of $my_var. All the logic should happens inside the index.php.

Edit

index.php

function replace_pattern($match)
{
    what should I write here
}
echo preg_replace_callback("/php\:\{(.*)\}/", "replace_pattern", $Content);

Edit 2

Variables are not declare in the global scope

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题