我能用PHP实现这个简单的事情吗?
基本上,我希望h1标记中的内容复制到h2标记。请看下面的例子我能用PHP实现这个简单的事情吗?,php,html,css,Php,Html,Css,基本上,我希望h1标记中的内容复制到h2标记。请看下面的例子 <!DOCTYPE html> <html> <body> <h1>whatever is inside here, needs to also be inside the H2 tag.</h1> <h2>whatever is inside h1 tag, it should also be here</h2> </body> &
<!DOCTYPE html>
<html>
<body>
<h1>whatever is inside here, needs to also be inside the H2 tag.</h1>
<h2>whatever is inside h1 tag, it should also be here</h2>
</body>
</html>
这里的任何内容都需要在H2标记中。
不管h1标签中有什么,它也应该在这里
在我的网站上,我有大约五个不同的标题标签,我需要手动将它们复制粘贴到每个标签上,所以我只想这样做一次,并使它们都相同。有两种方法可以实现。一个是由Fred ii提出的另一个是 您必须将
h2
标记与h1
绑定到某个类
像这样,
$("h2.def").html($("h1.abc").html());
$("h2.xyz").html($("h1.second").html());
工作
确保您尝试了Fred ii的建议,这个怎么样
<?php
$h1 = "i'm Heading 01";
$h2 = "i'm Heading 02";
?>
只需创建一个变量,并指定要在标题上使用的值:
<?php $title = "Stackoverflow!"; ?>
<!DOCTYPE html>
<html>
<body>
<h1><?php echo $title; ?></h1>
<h2><?php echo $title; ?></h2>
</body>
</html>
或者,如果要将其用于多个页面,请创建一个包含配置的单独文件,并将其包含在需要的地方
config.php
<?php $title = "Stackoverflow!"; ?>
page1.php
<?php include("config.php") ?>
<!DOCTYPE html>
<html>
<body>
<h1><?php echo $title; ?></h1>
<h2><?php echo $title; ?></h2>
<p>This is page 1!</p>
</body>
</html>
这是第一页
page2.php
<?php include("config.php") ?>
<!DOCTYPE html>
<html>
<body>
<h1><?php echo $title; ?></h1>
<h2><?php echo $title; ?></h2>
<p>This is page 2!</p>
</body>
</html>
这是第2页
根据注释中的说明,并添加说明:
回显可以在
标记内传递/回显的指定变量:
echo $var="<h1>whatever is inside here, needs to also be inside the H2 tag.</h1>";
<h2>Text<?php echo $var; ?> more text</h2>
echo$var=“此处包含的内容也需要位于H2标记内。”;
文本更多文本
页面中有多少个h1
标记?/code>将变量分配到it3到5h1
或h2
?echo$var=“此处的任何内容都需要在h2标记内。”代码>-文本更多文本
,如果这就是问题所在。如果没有,你需要给我们举个例子。不客气。我对上面的内容做了一点编辑,并在第一个变量声明中添加了echo
。
echo $var="<h1>whatever is inside here, needs to also be inside the H2 tag.</h1>";
<h2>Text<?php echo $var; ?> more text</h2>