/    Sign up×
Community /Pin to ProfileBookmark

php includes navigate parent html DOM

I have just redesigned my website and have just realised I may need to re do over 100 pages.

think of a directory listing site, all my navigation and wrappers etc are in includes, each of the city pages…NY.php, LA.php, etc just has the html for that city.

On each page I now need to load a text file, the text file will be called the same as the parent html div, eg in this example there would be a file Manhattan.txt and Queens.txt (the txt file will always have the same name as the container id)

[CODE]
<section class=”av_tab_section” itemscope=”itemscope” itemtype=”http://schema.org/CreativeWork” >
<div data-fake-id=”#Manhattan” class=”tab ” itemprop=”headline” >Manhattan</div>
<div id=”Manhattan-container” class=”tab_content “>
<div class=”tab_inner_content invers-color” itemprop=”text” >
<?php include(‘http://localhost/static/_includes/load_local_city_file.php’); ?>
</div>
…..
<div data-fake-id=”#Queens” class=”tab ” itemprop=”headline” >Queens</div>
<div id=”Queens-container” class=”tab_content “>
<div class=”tab_inner_content invers-color” itemprop=”text” >
<?php include(‘http://localhost/static/_includes/load_local_city_file.php’); ?>
</div>
[/CODE]

is it possible for php to navigate to parentNode.parentNode.nodeName ? and determine that it is inside the Manhattan-container & subsequently load the Manhattan file? and then further down the page it would determine it needs to load the Queens content.

or is my only option to add a javascript footer that looks for all “*-container” div’s, and for each look for a local file & then to an innerHTML update.
The content for the NY.manhattan would appear inside the manhattan container, queens inside the queens etc.

basically what I am trying to do is write a single “?php include(‘load_local_file’) ” and use it on all of the .php files, instead of a different include on each page (“?php include(‘load_manhattan_file’)…include(‘load_queens_file’)….include(‘load_la_file’)….etc )

I hope that make sense.

thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@Stephen_PhilbinDec 12.2014 — Iis it possible for php to navigate to parentNode.parentNode.nodeName ? and determine that it is inside the Manhattan-container & subsequently load the Manhattan file? and then further down the page it would determine it needs to load the Queens content.[/QUOTE]

[url=http://php.net/manual/en/class.domdocument.php]Yes[/url]. The DOM is not just a feature of Javascript. Many other languages also implement the DOM and PHP is no exception. The syntax is a little different and you might trip up on a few differences, but the documentation I've linked to should get you through the most common problems.

I came here to have a bit of a grumble about the documentation of the DOM in PHP (unlikely to effect anything you're trying to do here) and the post I'm about to make will have (very brief) examples of DOM use in PHP. I'll go and make my post and then come back and post a link to it in this thread so you can see a very basic example of its use to get you started.
Copy linkTweet thisAlerts:
@Stephen_PhilbinDec 12.2014 — Here you go. The following link is to a thread I made a few minutes ago. In the first block of PHP code, there's an example of making a new DOMDocument, giving it markup to use directly from a text string, creating a new element (p), adding text content to the "p" element and appending the element to the document as a child of the body element. If you're familiar with DOM in Javascript, then you'll already know more-or-less all of the functions you'll need to use with only a few exceptions.http://www.webdeveloper.com/forum/showthread.php?304235-DOMDocument-normalizeDocument%28%29-doesn-t-seem-to-work-as-described

Also, I'd strongly suggest [b]not[/b] using that [i]header('Content-Type: application/xhtml+xml; UTF-8');[/i] function call on the second-to-last line unless you understands the consequences of of using it and that you're happy to play by the rules of XML. It has practically nothing to do with your question and will not cause any problems if you ommit it; in fact it'll cause far fewer problems.

If you need it, the reference for PHP's DOM implementation is here http://php.net/manual/en/book.dom.php

Oh and this all assumes you're using PHP version 5.
×

Success!

Help @jojo77m spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...