SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to include() from specific lines?

    One can use the include() function to include the WHOLE file, but now I need to include certain parts of the file. Is that possible with include()? The file I want to include - or rather more correctly it´s parts - are HTML. I have googled all around, but have not found any answer. Please help.

  2. #2
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use a function to display your php/html

    PHP Code:
    function foo()
    {
      
    //php code here
      
    echo <<<HTML
      <!-- HTML CODE IS HERE -->
    HTML;


  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    break the file into parts?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I would like to do is like this: I have a file which consists of to divs:

    div pictures
    div news

    How can I include in a new php page ONLY the news div?

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like suggested to you:

    You make two files
    div_pictures.php
    div_news.php

    Or you make two functions
    div_pictures()
    div_news()

  6. #6
    SitePoint Zealot
    Join Date
    Oct 1999
    Location
    France
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a reason you can't split it into 2 files, one for each dov?
    --
    Veronica Yuill
    Archetype IT

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Couldn't you use a switch inside the included file?

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    To only include part of an include in certain pages you'd need to add code to the include to test what page it is being added to and then skip over the content that isn't wanted in that page.
    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="^$">

  9. #9
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know the exact code for it off the top of my head but I'd use file_get_contents to get the page into a string and then find a regex expert around here to help me construct a regular expression to strip out anything contained in a DIV named "news".. and then print that.
    |
    Add Your Robotics site to my Robot Directory: submit
    |
    Add Your Las Vegas Website to my Las Vegas Directory: submit


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
  •