更换指定的标记值看看下面的HTML例子:PHP:在PHP
<iframe width="AnyNumber" height="AnyNumber">
如何我可以替换任何数量指定数量的$ 1的宽度和高度2 $? 它们可以被替换为:
<iframe height="AnyNumber" width="AnyNumber">
更换指定的标记值看看下面的HTML例子:PHP:在PHP
<iframe width="AnyNumber" height="AnyNumber">
如何我可以替换任何数量指定数量的$ 1的宽度和高度2 $? 它们可以被替换为:
<iframe height="AnyNumber" width="AnyNumber">
它让我想起了模板。
例如,你有你喜欢这个
<div class="nav">@navigationMenu</div>
<img src="@imgSrc">
<span>@title</title>
<p>@article</p>
HTML文件,然后用一个简单的PHP类,你用需要的值替换,例如:
$this->registry->main_layout->set('imgSrc', './img/green.jpg');
有很多教程沿实现这一点的源代码(通常是一个简单的PHP类)。
$exmpl = '<iframe width="AnyNumber" height="AnyNumber">';
$exmpl = preg_replace('/(<iframe.*?width=").*?"/', "\${1}$argv[1]\"", $exmpl);
$exmpl = preg_replace('/(<iframe.*?height=").*?"/', "\${1}$argv[2]\"", $exmpl);
$ exmpl ='iframe width =“AnyNumber”height =“AnyNumber”>';
$ exmpl = str_replace('width =“AnyNumber”','width =“'。$ 1。'”',$ exmpl);您可以使用$ exmpl = str_replace('height =“AnyNumber”','width =“'。$ 2。'”',$ exmpl);
我不知道我理解你的问题。您是生成HTML还是解析它并尝试替换一些值? (至于属性顺序:无关紧要。) – Mat
如果你想在HTML中回显PHP变量,你可以像