www.webdeveloper.com
Results 1 to 7 of 7

Thread: Dispaly variables from text file

  1. #1
    Join Date
    Jan 2005
    Posts
    8

    Dispaly variables from text file

    Is it possible to take HTML code with embedded varibles ($variable) from a text file (fopen) and display on a results page? Works just fine when code is in the actual .php file but I couldn't get to work from text file.

  2. #2
    Join Date
    Jan 2005
    Location
    Illinois
    Posts
    815
    Well I'd have to see your code and the text file to see exactly what you're trying to do and what is going wrong. However, I believe you may find what you're looking for with the eval() function. That is for if you have PHP commands in the text file, is that the case?

    --Steve

  3. #3
    Join Date
    Jan 2005
    Posts
    8

    Code attached

    $show = "Dispaly Data";

    $display = fopen($filenamed, "r");
    flock($viewed, LOCK_EX);
    $page = fread($view, filesize($filenamed));
    fclose($viewed);
    echo "$page";

    Text File
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    stuff Here. $show.
    </body>
    </html>

  4. #4
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    In the text file:
    PHP Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    stuff Here. <?php $show ?>.
    </body>
    </html>
    In the script:
    PHP Code:
    $show 'some string';
    require(
    'text.file'); 

  5. #5
    Join Date
    Jan 2005
    Posts
    8

    Another problem.

    Getting closer.....works fine on webpage but not working when sending an email.

    $message = include('data.txt');
    $to = "acsdaily@yahoo.com";
    $subject = "Test";
    $headers = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success = mail($to, $subject, $message, $headers);

  6. #6
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    You can't use include like that. It returns a boolean not the file contents... the file contents is evaluated and sent to the browser. Here is one way you could use include().
    PHP Code:
    $flush;
    $show 'some string';
    ob_start();
    include(
    'data.txt');
    $message ob_get_clean();
    $to "acsdaily@yahoo.com";
    $subject "Test";
    $headers "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success mail($to$subject$message$headers); 
    Another:
    PHP Code:
    $show = 'some string';
    $message = file_get_contents('data.txt');
    $message = str_replace('<?php $show ?>', $show, $message); 
    $to = "acsdaily@yahoo.com";
    $subject = "Test";
    $headers = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success = mail($to, $subject, $message, $headers);
    Another:
    PHP Code:
    $show 'some string';
    $message file_get_contents('data.txt');
    $message = eval($message); 
    $to "acsdaily@yahoo.com";
    $subject "Test";
    $headers "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success mail($to$subject$message$headers); 
    None of those are ideal though. A better way would be to modify the text file:

    Text file
    PHP Code:
    $message '<html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    stuff Here. '
    .$show.'.
    </body>
    </html>'

    Script
    PHP Code:
    $show 'some string';
    require(
    'text.file')
    $to "acsdaily@yahoo.com";
    $subject "Test";
    $headers "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success mail($to$subject$message$headers); 
    Last edited by bokeh; 11-13-2005 at 09:53 AM.

  7. #7
    Join Date
    Jan 2005
    Posts
    8

    Thank you

    Thank you very much for your assistance.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles