Results 1 to 7 of 7

Thread: display external html list item in new page using php?

  1. #1
    Join Date
    Feb 2009
    Location
    Bristol UK
    Beans
    38
    Distro
    Ubuntu 10.04 Lucid Lynx

    display external html list item in new page using php?

    I am building a web page and, as is becoming increasingly routine for me, I have bitten off more than I can chew. I am even finding it hard to describe what I want to do

    mypage.html needs to display (possibly random) items from a list on another website.

    In my confused mind, I imagine the process like this (forgive the fake code : I had real problems displaying code on an earlier post )

    externalpage.html

    <html>

    <li> item one
    <li> item two
    <li> item three

    </html>

    mypage.html

    <html>
    <div>
    <php>
    I want to display <li> item (possibly random) here
    </php>
    </div>
    </html>

    The list item display will be part of a page and not the whole page.

    FYI : the person who has asked me to build this site does the following. They log on to externalpage.html and add items to the list (a photograph of a house and a description). mypage.html needs to display list items as examples of what is in the list. The full list is available using an iframe on mypage2.html.

    When I agreed to help build the site, I thought it was all going to be html. I know to ask questions now

  2. #2
    NoaHall is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Mar 2009
    Beans
    1,562
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: display external html list item in new page using php?

    First things first. Php is not declaired using <php> . It's <?php and ?>

    What you want to do is

    <?php echo "<li>" . $listitem . "</li>"; ?>

    By external, do you mean the webpage on a completely different site?
    Last edited by NoaHall; October 5th, 2009 at 07:28 AM.

  3. #3
    Join Date
    Feb 2009
    Location
    Bristol UK
    Beans
    38
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: display external html list item in new page using php?

    Yes. You are right. My php tags were awful.


    <?php echo "<li>"$listitem"</li>"; ?> This is exactly what I want to do, I think.

    The list items that I want to display are on another website.
    Last edited by esteeven; October 4th, 2009 at 02:28 PM. Reason: missing info

  4. #4
    Join Date
    Jul 2008
    Beans
    1,491

    Re: display external html list item in new page using php?

    Aside from the obvious security implications if you cannot trust the source of the content (and by this I mean you can also trust the source itself to be secure from attack); some ideas:

    In order of ‘robustness’
    1. Can you assume that the content can be treated as well-formed XML? In that case the answer is fairly trivial because you can use XSLT to extract relevant data; adapting to the precise structure of the document on the fly.
    2. Can you assume that you know where your data is (that is: can you assume a fixed structure)? In that case you can probably get away with loading the document into a DOMDocument object representation, then use that to extract data. Keep an eye on the necessary entity escape juggling!
    3. Can you assume fairly basic search criteria? In that case you might even be able to get away with a regular expression or similar ad-hoc approach. This is by far the less robust option which should only be used for such basic extraction operations as ‘all <li> elements in the document which contain just plain text’. Anything much more complicated and your regex will cost you not only much more time than full-blown XSLT stylesheets, it will also be far less reliable, certainly far less maintainable, and likely fail you at the first upgrade ...

  5. #5
    Join Date
    Feb 2009
    Location
    Bristol UK
    Beans
    38
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: display external html list item in new page using php?

    <?php echo "<li>"$listitem"</li>"; ?>
    What I don't understand in the above is how to get the $listitem data.

  6. #6
    Join Date
    Jul 2008
    Beans
    1,491

    Re: display external html list item in new page using php?

    Apart from the fact that there are 2 syntax errors in that statement...

    ... I was talking about an approach to extracting the data: not handing out ready-made code. Apart from security precautions; the rest is mostly implementation details anyone can look up on php.net anyways.

  7. #7
    Join Date
    Feb 2009
    Location
    Bristol UK
    Beans
    38
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: display external html list item in new page using php?

    Quote Originally Posted by Reiger View Post
    [*]Can you assume that you know where your data is (that is: can you assume a fixed structure)? In that case you can probably get away with loading the document into a DOMDocument object representation, then use that to extract data. Keep an eye on the necessary entity escape juggling![/list]

    I think I can assume a fixed structure and I am just about able to follow the "loading into a DOMDocument" but I can only see this as a way of identifying the data location itself.

    My limited knowledge stops me seeing how I can use php to actually extract/get to that data. I take your point about searching php.net and I have been doing this : am I on the right track with file_get_contents ?

    edit: nope. I hadn't understood the DOMDocument business but I do now. PHP can load the entire page as a DOMDocument and then I can extract / get to elements that I want to display because I have something I can extract from. Am I doing better??
    Last edited by esteeven; October 4th, 2009 at 08:38 PM. Reason: dawning of understanding

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
  •