SO中文参考
首页
(current)
程序语言
c
java
python
c++
go
javascript
swift
c#
操作系统
linux
ubuntu
centos
unix
数据库
oracle
mysql
mongodb
postgresql
框架
node.js
angular
react-native
avalon
django
twisted
hadoop
.net
移动开发
android
ios
搜索
使用 PHP 缓冲区缓冲更多信息<!--TITLE--></titl...</desc> <question vote="0"> <p>我正在寻找缓冲更多文本的解决方案。我有以下内容(<a href="https://stackoverflow.com/questions/3463716/set-page-title-using-php">使用 PHP 设置页面标题</a>)</p> <pre><code><? ob_start (); ?> <!DOCTYPE> <head> <title><!--TITLE--></title> </head> <body> <? $pageTitle = 'Title of Page'; // Call this in your pages' files to define the page title ?> </body> </html> <? $pageContents = ob_get_contents (); // Get all the page's HTML into a string ob_end_clean (); // Wipe the buffer // Replace <!--TITLE--> with $pageTitle variable contents, and print the HTML echo str_replace ('<!--TITLE-->', $pageTitle, $pageContents); ?> </code></pre> <p>它仅适用于标题,但我想缓冲 4 个信息,如下所示:</p> <pre><code><? ob_start (); ?> <!DOCTYPE> <head> <meta property="og:title" content="<!--TITLE-->" /> <meta property="og:url" content="<!--URL-->" /> <meta property="og:image" content="<!--IMG-->" /> <meta property="og:description" content="<!--DESCRIPTION-->" /> </head> <body> <? $pageTitle = 'Title of Page'; $pageUrl = 'http://anything.com'; $pageImg = 'http://anything.com/lol.png'; $pageDesc = 'One sentence is here'; ?> </body> </html> <? $pageContents = ob_get_contents (); ob_end_clean (); echo str_replace ('<!--DESCRIPTION-->', $pageDesc, $pageContents); echo str_replace ('<!--IMG-->', $pageImg, $pageContents); echo str_replace ('<!--URL-->', $pageUrl, $pageContents); echo str_replace ('<!--TITLE-->', $pageTitle, $pageContents); ?> </code></pre> </question> <answer tick="true" vote="2"> <p>您正在回显页面内容 4 次。不要这样做,而是再次将替换结果放入 pagecontent 变量中并最后回显一次</p> <pre><code>$pageContents= str_replace ('<!--DESCRIPTION-->', $pageDesc, $pageContents); $pageContents= str_replace ('<!--IMG-->', $pageImg, $pageContents); $pageContents= str_replace ('<!--URL-->', $pageUrl, $pageContents); $pageContents= str_replace ('<!--TITLE-->', $pageTitle, $pageContents); echo $pageContents; </code></pre> </answer> </body></html>
问题描述
投票:0
回答:0
php
最新问题
VS Code 无法运行文件名中包含引号的脚本
<?php comments_template('', true); ?>不起作用
去“mod init”创建新文件夹?路径的意义是什么?
在通知中显示图像 iOS - Expo 管理工作流程
将本地 Azure DevOps Server 配置为默认网站下的 IIS Web 应用程序,而不是在新网站上?
Astronvim:如何安装neotest-jest?
VS Code 无法运行简单的“Hello World”脚本
如何从 TeamCity 获取 teamcity.build.branch
Cucumber 场景大纲标题不读取示例数据,数据未读取且列标记为未使用
何时指定PagingInfo.PagingCookie和PagingInfo.PageNumber
VScode 无法运行简单的 Hello World 脚本
在vendor/magento/module-email/Model/AbstractTemplate.php中的字符串上调用成员函数getFormattedAddress()
用等量值或多个值替换检测到的异常值
如何在 HTML Purifier 中删除 img 标签的 alt 属性?
旋转排序数组中的最小值
npm 无法在 Windows 中与 Nodejs 一起正确安装
Django:我什么时候需要 __eq__ 方法?
如何在 REST 中处理子集合的分页
为什么这段代码会让我的电脑崩溃,不仅是我的电脑,还有我的朋友?
UML 状态图 - 从元状态退出复合状态是否合法
© www.soinside.com 2019 - 2024. All rights reserved.