dongming8867 2015-05-04 19:20
浏览 28
已采纳

在PHP中更改DIV包含[关闭]

I'm new to this site and VERY new to HTML/PHP so pardon me if I do anything wrong... but here's my question:

I just started learning HTML through many Google searches. 2 weeks ago I had never touched HTML in my life. I'm building a site with 6 main pages: Home, Questions, Forums, Contact, About, and Help.

Each page has 4 main components:

Header (including horizontal navbar)

Sidebar

Main Content Area

Footer

The Header, Sidebar, and Footer are replicated on each page using the PHP INCLUDE command. This works great. Everything is working fine.

However, I don't exactly want the Header/Navbar to be 100% identical on each page. In my Header.HTML file (the file that is called upon by my PHP INCLUDE command) contains a DIV I rightfully called "headertext".

For example, on the home page, my headertext DIV says "Cool Stuff, Free of Charge!" (visually styled with CSS, but the text information is contained within the Header.HTML file) and it's centered nicely between the website logo and the website ad box, all within the Header area.

Since I'm using PHP INCLUDE, EVERY page on the site has this same line of text in the header. However... here's what I want:

When I navigate to my "ABOUT" page for example, I want the headertext div to become "ABOUT US" instead of "Cool Stuff, Free of Charge".. Get what I'm saying?

But I still want to use PHP INCLUDE to minimize the amount of code I have to sift through for each page's index.php file...

I hope all of this made sense.... While I am a newbie to this stuff, I've grown to become pretty good at HTML over the past 2 weeks. However, please note that I am brand new to PHP (as of today). So is this possible?

Thanks for any help!


UPDATE: SOLVED:

Thanks to Kainaw, I figured it out.

  • 写回答

2条回答 默认 最新

  • dsadsa123111 2015-05-04 19:25
    关注

    A very simplistic way to do it...

    In the included header PHP file, make the text a variable:

    if(empty($headertext)) $headertext = 'Cool Stuff, Free of Charge';
    

    Then, when you print the data, do something like:

    <div id='header'><?php echo $headertext; ?></div>
    

    Finally, in your about.php file, before you include the header.php file, you set what you want the text to be (I'm guessing at the file names)...

    $headertext = 'About Me Page';
    include('header.php');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘