Skip navigation
thegrayrock@gmail.com
Currently Being Moderated

DIV content read from a file

Nov 22, 2012 6:31 PM

I need to create an HTML web page where the content with a DIV is read form a file.  I have gotton PHP to work within DreamWeaver and can read the arguments of the text file.  Dream Weaver won't let me put the <Div ...> staement witih the PHP code (generates a red error).  Also, I am not sure how to pass the argument $field1 into the DIV statement between the > and < .

 

Can I pass variables from PHP code into the HTML code?

Can I use these values withi a DIV statement?

 

Much thanks to anyone who can explain how I might do this.

Rick

 

 

<?php

$line=0;

$file_handle = fopen("text.txt", "r");

while (!feof($file_handle)) {

    $line=$line+1;

    list ($field1, $field2, $field3) = fscanf($file_handle, "%s %s %s");

    print "Line $line: field1 is $field1\tfield2 is $field2, and field3 is $field3<p></p>";

    }

fclose($file_handle);

 

?>

 

<div id="apDiv1">$field1</div>

 
Replies
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Nov 22, 2012 8:39 PM   in reply to thegrayrock@gmail.com

    Try this:

     

    <div id="apDiv1">

    <?php echo '<p>' . $field1 . '</p>'; ?>

    </div>

    I'm printing the $field1 definition within a <p> paragraph tag inside apDiv1.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 23, 2012 5:40 AM   in reply to thegrayrock@gmail.com

    Using an absolutely positioned element to hold text content is dangerous, you know?  Why are you using it instead of just a default positioned div?

     

    Anyhow, you can also achieve Sudarshan's suggestion this way -

     

    <div>

    <p><?php echo $field1; ?></p>

    </div>

     

    I prefer to keep my HTML as much as possible as actual HTML, and not embedded in PHP.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points