SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    loadHTMLFile for PHP files

    Hello everyone. I am trying to add some dynamic content to a page that contains PHP code. When I use the loadHTMLFile function to do this, the PHP tags <?PHP ?> are replaced by &lt?php ?&gt, corrupting it. It also raises a whole bunch of DOMDocument::loadHTMLFile(): htmlParseEntityRef: no name in... errors. All I'm trying to do is add some checkboxes to the page according to data retrieved from the database, and I believe that such action requires the use of the DOM getElementById, createElement, setAttribute and appendChild functions, which in turn requires that the page be loaded with the PHP loadHTMLFile function.

    Can anyone help, please?


    Thanking you,
    Sofia

  2. #2
    SitePoint Addict
    Join Date
    Aug 2013
    Location
    New Zealand
    Posts
    277
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I haven't heard of anyone loading a php file that way in a webserver context. Usually you name the file with a .php extension and the web server does the right thing. What web server are you using?

  3. #3
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Kiwiheretic. The PHP file works fine on the server. The problem is, after being parsed with the PHP loadHTMLFile function, the PHP function tags get corrupted. After that, the page still displays properly, but the PHP functions don't execute because the opening and closing tags <?PHP ?> have been replaced with &lt?php ?&gt.

    The page that I'm trying to load is essentially HTML content, nested with some PHP echo functions to validate form inputs; something like:
    <input type="text" ... value="<?php echo (isset($_POST['name'])) ? $_POST['name'] : ''; ?>".
    After being parsed by loadHTMLFile, they're changed to:
    <input type="text" ... value="&lt?php echo (isset($_POST['name'])) ? $_POST['name'] : ''; ?&gt".

    I'm using the loadHTMLFile function to be able to add dynamic content to it. Unless there's any other way to add dynamic HTML content from PHP?

    Thanks again.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    That function is for loading HTML not PHP.

    Can't you just include or require the file instead?
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi felgall. If I were to use include, would I still be able to create new elements and append them to the content? I'm assuming that the included file would not be saved, so would there be a way to display the content along with the new elements?

    Thank you.


Bookmarks

Posting Permissions

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