Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post

    view results of different php files

    i've got this code that gets the price of items from amazon.com and that works, but i dont know how to connect a certain spot on a separate page to output the results of that code that is in a separate php page. i tried using the following code, but that just put out the php code itself, not the results of the code..

    PHP Code:
    <?php
            $fh 
    fopen("prices.php""r");

    while(!
    feof($fh)){

           echo 
    fgets($fh4096);

    }

    fclose($fh);
                  
    ?>
    Last edited by boeing747fp; 01-20-2004 at 12:42 AM.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    eval()

    http://be.php.net/manual/en/function.eval.php

    I use it a lott lately to pull PHP code from a db or to dynamically compose the PHP code and then execute it

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    An other option is to use ob_start()/ob_end() to control your output buffers ..... you can mess around with any parsed data before echoing it out.

    More info can be found at: function.ob-start.php

    stuartc1
    -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
    www.php-editors.com - PHP Editors Reviewed
    www.phphub.com - PHP Community Hub
    www.php-freelancers.com - PHP Freelance Jobs
    -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    where in the above code i posted would i put the eval() part?

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
            $fh 
    fopen("prices.php""r");

    while(!
    feof($fh)){
        
    $lineofcode=fgets($fh4096) ;
        eval(
    $lineofcode);
    }

    fclose($fh);
    ?>
    So supposing that prices contains the php code

    $total = $first + $last;
    echo $total;

    Then the first iteration wount output anything, but would compute the value for $total.
    The second iteration would print the value of $total.

    But there is no real reason to read the file line by line ...

    If prices.php is a php-file, then you can just as well include it like
    include ('./prices.php');
    and then the files code will automatically be parsed, as if the code from that file was part of the file where you include it in. (Like if you would copy-paste it into your script.).
    The result would be the same as in your code, if you use the eval function on each line.

    So you should only use the eval() if you want to only parse parts of the file (Like for instance, if you would like to run a check on the files content to verify that it isn't dangerous or to filter out some specific lines, and only execute these lines of the file.
    Last edited by raf; 01-22-2004 at 07:19 AM.

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    i tried that code u just gave me and all it does is make all my images broken.

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by boeing747fp
    i tried that code u just gave me and all it does is make all my images broken.
    What sort of feedback/help do you expect on this?

  • #8
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    what is causing the images to break when i put the following code at the top of the php code, and not be broken when it's not in.

    <?php include("princes.php"); ?>

  • #9
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe someone else understands what you mean, but to me it doesn't make sense. You need to supply more info, like for instance the code you want to inlude or eval()

    I never heard of a broken image.
    The code i gave doesn't have an include in it "and all it does" is execute the php-doce like i illustrated in that post, which means that your prices.php fiel can only contain php-code, without the php tags.
    If you want to print an image by eval()'ing the code inside prices.php then prices.php should contain

    echo('<img src="/foo.gif" alt="bar" border="0">');

    If you want to get the content through an include, then your fle needs to look like

    <?php
    ...
    echo('<img src="/foo.gif" alt="bar" border="0">');
    ...
    ?>


  •  

    Posting Permissions

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