Formatting or replacing code after php include

Discussion in 'PHP' started by mgrohan, Sep 5, 2008.

  1. #1
    I currently have the following pieced together to include a file (unformatted plain text file) on a webpage:

    <?php
    $URL = "http://mysite.com/".$page."";
    include ("$URL");
    ?>

    The include works fine however when viewing the webpage with the include the page appears as:
    apple banana mango

    I have been trying without success now to get the included plain text file to have <br /> so that it will display as:
    apple
    banana
    mango

    What is the way to do this. I have played around with str_replace and preg_replace but my knowledge of php is very basic (non-existant).

    Thanks for any help.
     
    mgrohan, Sep 5, 2008 IP
  2. pubdomainshost.com

    pubdomainshost.com Peon

    Messages:
    1,277
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am not able to relate $URL with apple mango and banana ... could you give better example ?

    Assume that include tag would only copy the content of file / data you wish to include, so if I add include in a page called mypage
    mypage {--------------lots of code--------------------}
    addthis {somecode}

    so if i include addthis in mypage...
    mypage {--------------lots of code----------- include (addthis)---------}
    it (mypage) would be finally processed as
    mypage {--------------lots of code-----------{somecode}---------}

    HTH,
     
    pubdomainshost.com, Sep 5, 2008 IP
  3. mgrohan

    mgrohan Active Member

    Messages:
    671
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    58
    #3
    OK, not too clear..

    <?php
    include ("http://mysite.com/".$page."");
    ?>
    Code (markup):
    ...includes an plain text file in the page.

    I would like to somehow edit the file before it is displayed.

    i.e. replace the space or newline which it has now, with <br />
     
    mgrohan, Sep 5, 2008 IP
  4. pubdomainshost.com

    pubdomainshost.com Peon

    Messages:
    1,277
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK
    So save the text file with the format you would like to display it in!
     
    pubdomainshost.com, Sep 5, 2008 IP
  5. mgrohan

    mgrohan Active Member

    Messages:
    671
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    58
    #5
    I know that would work, but i need it in 2 different formats on 2 websites. Which is my i am trying to do it..
     
    mgrohan, Sep 5, 2008 IP
  6. mgrohan

    mgrohan Active Member

    Messages:
    671
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    58