Results 1 to 4 of 4

Thread: [RESOLVED] Storing Static Page Data

  1. #1
    Join Date
    Aug 2008

    resolved [RESOLVED] Storing Static Page Data

    Hi. I'm new.

    I've been making web sites for just over 10 years but in the past few years, I've been striving toward the paradigm of separation of style, structure, and content. I love that it keeps everything so organized and accessible.

    So my latest project, I've been taking this concept to as far of an extreme as I can. What I want to do is create a file that contains all of the data for a particular page, which may include the title, main body text, and other section-specific text, and then have my structural skeleton call each part through a php include.

    My problem is that I'm not sure how I should structure my page-data file to facilitate php insertion while keeping it as simple and readable as possible.

    One way that I've done it is to code the data file as a php file and call each section with functions that dump text/HTML. This seems overly complicated and inelegant. I've also tried saving HTML code as PHP variables, but I've been running into problems with existing code having quote marks in the text or attributes, and although I could slash them out, I'd like a more elegant solution if it exists.

    I've also considered using XML, but I'm not sure how easy it is to store HTML data as a single XML node and call it using php.

    Ideally, I would like something to the extent of :

    title: Welcome to Page A
    body: This is my body with <b>HTML</b> code
    sectionA: This text goes in the section A area of page A
    i.e. all page relevant data in one file, where each section is then called to the correct location with PHP.

    Does that make sense? Any thoughts are appreciated!!

    Thanks in advance!

  2. #2
    Join Date
    Aug 2008
    Hi again:

    I figured out how to use XML (relatively) elegantly to store page data with sections that have HTML tags.

    I stumbled across the CDATA tag that, once surrounded, all inner text is left unparsed, which means I can put in HTML or scripts without worrying about escaping characters.

    Here's an short example of how I'm using it:

    pagedata.xml (storing data):
    <?xml version="1.0" encoding="utf-8" ?>
    <rss version="0.91">
    <title>Hi there!</title>
    Welcome to my page!  Check out this <a href="blah.html">link</a>!
    index.php code (structure):
    PHP Code:
    //load in xml using simplexml_load_file(filename)
    //normally, datafile selection is determined from url parsing
    //    e.g. index.php?page=home tells me to get home.xml
    //but for demonstration, I'll just stick in the xml file from above
    $data simplexml_load_file("pagedata.xml");?>
    <title><?php print $data->title?></title>
    <?php print $data->body?>
    This code will insert the relevant sections and the HTML data surrounded by CDATA will be inserted as normal text:

    index.php output:
    HTML Code:
    <title>Hi there!</title>
    Welcome to my page!  Check out this <a href="blah.html">link</a>!
    So far, I really like this solution. The output is clean and along with mod_rewrite on Apache, all server-side activity is hidden. There's no dealing with unnecessary and messy client-side construction, i.e. using Javascript to handle XML. The xml data file has very little overhead, and is easy to read, modify, and extend. And thanks to simplexml, the page construction is indeed simple.

    Any questions and comments are welcome. I'm still relatively new at this separation paradigm, but I'm really liking it so far.

    Here are some links that were helpful to me:
    CDATA description

  3. #3
    Join Date
    Aug 2008
    EDIT that XML file should not be using rss tags obviously. That was a copy/paste oversight.

    <?xml version="1.0" encoding="utf-8" ?>
    <title>Hi there!</title>
    Welcome to my page!  Check out this <a href="blah.html">link</a>!

  4. #4
    Join Date
    Nov 2003
    Jerryville, Tejas
    99% of the power of XML is the fact that you have DOM or SAX type parsers available in essentially every programming language which renders the old bugaboo of flat file parsing moot.
    "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." Brian W. Kernighan

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.46869 seconds
  • Memory Usage 2,870KB
  • Queries Executed 13 (?)
More Information
Template Usage (35):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates