Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有了PHP,我怎样才能在我的内容模板中加载一个锚定的部分,基于id从文件名读取?_Php_Include Path - Fatal编程技术网

有了PHP,我怎样才能在我的内容模板中加载一个锚定的部分,基于id从文件名读取?

有了PHP,我怎样才能在我的内容模板中加载一个锚定的部分,基于id从文件名读取?,php,include-path,Php,Include Path,下面是我的布局: randompagenumber.php | | / | header.php php include -| content.php \ | footer.php 页脚有一个php脚本,它调用randompagenumer.php的文件名,删除其扩展名和名称中的破折号,并将该文件名的编号作为页码输出到下角。 (左或右,取决于该数字是偶数还是奇数) 我有几页(现在是10页),

下面是我的布局:

    randompagenumber.php
             |
             |
           / | header.php
php include -| content.php
           \ | footer.php
页脚有一个php脚本,它调用randompagenumer.php的文件名,删除其扩展名和名称中的破折号,并将该文件名的编号作为页码输出到下角。 (左或右,取决于该数字是偶数还是奇数)

我有几页(现在是10页),我叫它们--1.php、-2.php、-3.php、-4.php、-5.php、-6.php、-7.php、-8.php、-9.php、-10.php

所以脚本将它们简单地转换为1,2,3,4,5,6,7,8,9,10

我拥有的页脚代码:

<?php
$pagenr = basename($_SERVER['PHP_SELF']);
$pagenr = str_replace( array( '.php', '.htm', '.html', '-', '_' ), '', $pagenr ); // Remove extensions and spaces in filename

if ($pagenr % 2 == 0) {
$footlr = "footerlinks";
$pcontainer = "pcontainerl";
} else{
$footlr = "footerrechts";
$pcontainer = "pcontainerr";
}
?>

<div id="<?=$footlr?>">
<div id="pnummer" class="pcontainer"><?=$pagenr?></div>


使用解决方案更新

所以我成功了

首先是my content.php:

<?php
?>
...some div's with page id's here...
<div id="p5">
<div id="contentwrapperpaginas">Content from page 5</div>
</div>
<div id="p6">
<div id="contentwrapperpaginas"><p style="color:yellow;margin-left:-25px;">Content from page 6</p></div>
</div>
...some more div's with page id's here...

…某个有身份证的分区在这里。。。
第5页的内容
第6页的内容

…这里还有一些有页面id的分区。。。
因此,通过下面的脚本,我让它只加载一个div及其内部元素。复制/粘贴中使用的示例将加载
。脚本位于index.php内,并加载了

$url = 'templates/content.php';
$content = file_get_contents($url);
$first_step = explode( '<div id="p6">' , $content );
$content_div = explode("</div>" , $first_step[1] );
$url='templates/content.php';
$content=file\u get\u contents($url);
$first_step=分解(“”,$content);
$content\u div=explode(“,$first\u step[1]);

解决方案是将
更改为

它将始终加载整个页面,锚定用于“跳转”您指定的部分感谢您的快速回复,@RomainB。在计算randompagenumber.php编号后,是否有办法只在页面加载上列出所需的锚定项?
<?php
?>
...some div's with page id's here...
<div id="p5">
<div id="contentwrapperpaginas">Content from page 5</div>
</div>
<div id="p6">
<div id="contentwrapperpaginas"><p style="color:yellow;margin-left:-25px;">Content from page 6</p></div>
</div>
...some more div's with page id's here...
$url = 'templates/content.php';
$content = file_get_contents($url);
$first_step = explode( '<div id="p6">' , $content );
$content_div = explode("</div>" , $first_step[1] );