页面的动态标题? PHP包含链接? [英] Dynamic Title of page? PHP include links?

查看:63
本文介绍了页面的动态标题? PHP包含链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面的标题(头部内容,而不是随机标题)是否可以动态显示? 我认为PHP可以返回当前页面的值然后在修改它之后将其回显到Title标签中。



我说要修改它,因为我使用骆驼大小写,并且需要将userProfile.php转换为用户配置文件的方式



$ p

我曾经用过:

<$ p $ ($ _ SERVER [SCRIPT_NAME],strpos($ _ SERVER [SCRIPT_NAME],/)+ 1)public function findCurrentPageURL(){

return substr ;

} //结束返回当前页面

作为函数和思想编辑:我不知道如何说这个,但在这里,我希望在一个简单的答案,因为我可以'', t

我有一个包含各种类和其他文件的init.php文件。



当所有调用它的页面都在同一个文件夹中时,它可以正常工作。现在我需要在主目录下创建一个子目录:

  coreFolder 
- > init.php
- >类
- > - > class.php
index.php
other.php
otherFolder
- > otherPage.php

就是我现在拥有的一个例子。



在index(和其他)中我的调用是 require'core / init.php'



在init.php中,I有

 需要'core / connect / dbConnect.php'; 
需要'core / classes / users.php';
等etc

现在我遇到的问题是当我尝试调用init我的otherPage.php我必须使用 include'../ core / init.php'



然后我得到错误,因为它无法找到其他包含在init.php中。



请问有解决方案吗?我真的宁愿没有一个伟大的PHP文件长长的列表



然后我可以将两者结合起来,并且瞧!

标题标记中输出函数的返回值就是这样:

b
$ b

 < title><?php echo findCurrentPageURL(); ?>< /标题> 

在一个php页面中。



按照你的想法拆分它,参见Orangepill对问题的评论,将你的问题链接到使用php preg_match(正则表达式)将单词camelCase分成单词


Can the Title of the page (within the head, not a random title) be dynamic?

I was thinking that PHP could return the value of the current page and then echo it into the Title tag after amending it.

I say amending it as I use camel case and I'd need a way of turning userProfile.php into User Profile

Can anyone point me in the right direction please?

I've used :

public function findCurrentPageURL(){

return substr($_SERVER["SCRIPT_NAME"], strpos($_SERVER["SCRIPT_NAME"], "/")+1);

}//end to return current page

as a function and thought that the same principle could be applied.

EDIT: I'm not sure how to word this but here goes, I'm hoping on a simple answer as I can't see this being a rare issue.

I have an init.php file that includes various classes and other files.

This gets called at the top of every page.

It works fine when all the pages that call it are in the same folder. Now I need to create a subdirectory within the main so:

coreFolder
->init.php
->classes
->->class.php
index.php
other.php
otherFolder
->otherPage.php

is an example of what I have now.

In index(and others) my call is require'core/init.php'

In init.php I have

require 'core/connect/dbConnect.php';
require 'core/classes/users.php';
etc etc

The problem I'm now having is when I try and call init from my otherPage.php I have to use include'../core/init.php'

I then get errors as it cannot locate the other includes within init.php.

Is there a solution for this please? I really would prefer to not have one uber great big long list of php files

I can then combine the two and voila

解决方案

To output the return value of your function in the title tags just put it this way :

<title><?php echo findCurrentPageURL(); ?></title>

in a php page.

Also to split it as you want, see Orangepill comment to the question, linking your question to Split camelCase word into words with php preg_match (Regular Expression) .

这篇关于页面的动态标题? PHP包含链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆