简体   繁体   English

使用PHP Include分割标签

[英]Splitting tags with a PHP Include

So I'm setting up a portfolio and print selling website, and a lot of the text on the individual product pages is going to be generic. 因此,我建立了一个投资组合和印刷销售网站,各个产品页面上的许多文字将变得通用。 To avoid typing and make updates easier I'm thinking about heavily using php includes. 为了避免输入并使更新更容易,我正在考虑大量使用php include。 I'm wondering if it's safe to split a paragraph (or other) tag into a PHP include, like this: 我想知道将段落(或其他)标记拆分成PHP包含是否安全,如下所示:

<p>This image, [title], photographed at the Biltmore Gardens in late Summer 2015, <?php include '../include/generictext.php';?>

And then generictext.php would have the closing paragraph tag: 然后,generictext.php将具有结束段落标签:

is printed on Canson Infinity Platine Fibre Rag 310. This excellent fine art paper offers blah blah blah</p>
The following sizes are available:<br>
...

Is that safe? 这样安全吗?

Yes, that's perfectly safe. 是的,那绝对安全。 The only thing the PHP interpreter looks for in this context is <? PHP解释器在这种情况下唯一需要查找的是<? ; ; everything else gets passed through unchanged, so it doesn't matter that the include() happens in the middle of a paragraph. 其他所有内容都保持不变,因此include()在段落的中间并不重要。

It's even safe (albeit confusing) to put an opening PHP tag in the middle of an HTML tag, eg 将开头的PHP标记放在HTML标记的中间甚至很安全(尽管令人困惑),例如

<div class="<?php include "blah" ?>">

I had a similar set up before moving my site to a database, the URL would point to a php page containing only variables, then that page would include another containing the template for output, eg. 在将网站移至数据库之前,我进行了类似的设置,URL指向仅包含变量的php页面,然后该页面将包含另一个包含输出模板的页面,例如。

thisprint.php thisprint.php

<?php
$title = 'nice photo';
$location = 'some place';
$date = 'summer 2015';

include 'template.php';
?>

template.php template.php

<p>This image, <?= $title ?>, photographed at <?= $location ?> in <?= $date ?>, is printed on Canson Infinity Platine Fibre Rag 310. This excellent fine art paper offers blah blah blah</p>
The following sizes are available:<br>
...

This works great for smaller sites, but as I found out becomes difficult to maintain/expand as the site gets bigger and bigger and this is where a database comes into its own. 这对于较小的站点非常有用,但是随着站点越来越大,我发现维护/扩展变得越来越困难,而这正是数据库自成体系的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM