1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

echo stuff

Discussion in 'PHP' started by Joseph S, Jul 13, 2008.

  1. #1
    I am trying to echo a file content (php stuff).

    So I have text.php for instance with this:
    <? $test='test';?>
    Code (markup):
    I have another php file, test1.php where I have this:
    <? include('text.php');?>
    Code (markup):
    After that include I am trying to find something that will echo everything (what I included) as a php code. So, my page should look like this:
    <? $test='test';?>
    Code (markup):
     
    Joseph S, Jul 13, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Do you want to print the file content without execute the php code? is that what you want.
     
    php-lover, Jul 13, 2008 IP
  3. Joseph S

    Joseph S Well-Known Member

    Messages:
    1,373
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    155
    #3
    Yes. Everything as a php file.
     
    Joseph S, Jul 13, 2008 IP
  4. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Put this code in your test1.php file.

    highlight_file('text.php');
     
    php-lover, Jul 13, 2008 IP
  5. Joseph S

    Joseph S Well-Known Member

    Messages:
    1,373
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    155
    #5
    Thanks. This helps me a lot. I didn`t know about this method.
     
    Joseph S, Jul 13, 2008 IP
  6. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #6
    You welcome :)
     
    php-lover, Jul 13, 2008 IP
  7. Joseph S

    Joseph S Well-Known Member

    Messages:
    1,373
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    155
    #7
    I have another echo problem now.:)

    I don`t know how to add a php echo into javascript. :(
     
    Joseph S, Jul 14, 2008 IP
  8. revvi

    revvi Peon

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Make sure the javascript is within a php file. Surely it will be parsed by php.
     
    revvi, Jul 14, 2008 IP
  9. Joseph S

    Joseph S Well-Known Member

    Messages:
    1,373
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    155
    #9
    Something else seems to be the problem.

    The code above doesn't return anything.


    returns Resource id #34 if used in the above code.


    [edit]
    used in phpmyadmin returns the result I need.
     
    Joseph S, Jul 14, 2008 IP
  10. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #10
    <?
    require_once('./settings.php');

    $sql = 'SELECT * FROM `currency` LIMIT 0, 30 ';
    $result = mysql_query($sql);


    if(!$result) die("Query Failed.");

    while($row = mysql_fetch_row($result)) {
    /* Put something in here, perhaps to test just: */
    var_dump($row);
    }
    ?>
     
    Danltn, Jul 14, 2008 IP
  11. Joseph S

    Joseph S Well-Known Member

    Messages:
    1,373
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    155
    #11
    Okay, that works but I still can not echo $result; :(
     
    Joseph S, Jul 14, 2008 IP
  12. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #12
    Err... you just said you could: Resource id #34...

    The return value of mysql_query is a resource, not a string or an int... etc

    Dan
     
    Danltn, Jul 14, 2008 IP
  13. rhadoo82

    rhadoo82 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Try this

    <?
    require_once('./settings.php');

    $sql = 'SELECT * FROM `currency` LIMIT 0, 30 ';
    $result = mysql_query($sql);


    if(!$result) die("Query Failed.");

    while($row = mysql_fetch_row($result)) {
    echo $row['id'];
    }
    ?>
     
    rhadoo82, Jul 14, 2008 IP
  14. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #14
    You are right there, just save the javascript with a .php extension - and if you want - just for security - add a header defining the content as Javascript. You can do this by, adding at the top of the PHP fie you wish to use as JS:

    
    <?php
    header('Content-type: text/javascript');
    ?>
    //Javascript goes here.
    
    PHP:
    And..eurgh, clean up your HTML - keep tags in lowercase. That should be:

    
    <script type="text/javascript">
    <!-- 
    window.location='<?php echo $url;?>';
    // -->
    </script>
    Code (markup):
     
    blueparukia, Jul 14, 2008 IP