从php中检索单个值


retrieve single value from php

我需要从html文档中的php文件中检索单个值,但问题是php文件稍后被调用,超过了我想包含该值的点。

,

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<title><? php echo $pro_title ?></title> <!-- Can't retrieve value -->
<meta name='Description' content='<? php echo $pro_title ?>' /> <!-- Can't retrieve value -->
<meta name='Keywords' content='<? php echo $pro_title ?>' /> <!-- Can't retrieve value -->
</head>
<body>
<!-- Header -->
<?php include ("header.html") ?>
<!-- Content Area Start -->
<?php include ('product.php') ?> <!-- Okay --> 
<!-- Content Area End --> 
<!-- Footer -->
<?php include ("footer.html") ?>
</body>
</html>

是否有一种方法可以引用单个php值而不包括整个文件,以及保留其包含的内容?

假设在product.php你有一些查询或逻辑,帮助你检索$pro_title,也许,如果你不想重构你的页面,你应该削减这个逻辑,并把另一个php文件(例如:product_header.php),然后包括在顶部。product_header.php中的变量可以稍后在product.php脚本中使用。

我修复了这个问题,因为我的php文件只是运行一个while循环,所以我在它上面添加了一个函数,然后在我的html正文区域调用这个函数作为内容。然后,我在原来的函数下面添加了另一个函数,用于title和$title。

很抱歉打扰你们所有人,但是你知道当你感到被困住的时候,就像在树林里迷路一样,可怕!!问候,史蒂夫。