Jump to content

Is possible to put plain text in HTML by PHP?

Recommended Posts

Hello everyone,

I'm trying to get abbreviate states from plain text into HTML select and option, seem it's not working. Can you help me? here my PHP code:

/* Read file to insert as option in HTML */

$file = fopen("States.txt","r") or exit("Unable to read");
    while(!feof($file)) {
        $states = fgets($file);
        $statelist =  "<option value='".$states."'>".$states."</option>";


<tr><td>State:</td><td><select id="abb" name="abb"><?php echo $statelist ?></select></td></tr>

Thank you for help

Edited by Sigmahokies
Link to post
Share on other sites

I don't see anything obviously wrong with the code. Does the text file exist in the same folder as your PHP file?

Link to post
Share on other sites

Apart from where it will only show the last option everytime. (.= required to append each option)

$statelist .=  "<option value='".$states."'>".$states."</option>";


Edited by dsonesuk
  • Thanks 1
Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...