We: First steps in doing php in html

15 January 2022 (and before)

Yesterday, I worked on getting a simple ‘hello world php program to run on my web page.’

First steps in doing php within html

What I learned

  • a file that has a php suffix.
  • php and html files differ considerably in their syntax; they also use different comment characters
  • in working with php it must be run from the server (in contrast to html which can be executed locally)
  • in working with php, it is very helpful to display the web page source – this allows you to see how the php is generating html on the server.
  • To run on my web site, the php must be within a file that has a php suffix
  • It is a good idea to use the long form of the tag <?php ?>
  • php and html files differ considerably in their syntax; they also use different comment characters
  • in working with php it must be run from the server (in contrast to html which can be executed locally)
  • in working with php, it is very helpful to display the web page source – this allows you to see how the php is generating html on the server. ]

What I don’t know / Want to figure out

  • how to get php working when I want my basic page to be named index .html

using php to randomly load content from a file

Today I worked on trying to get a php script to load random images and other content onto my page. I found a php program called “randy.php” that does this sort of thing; it pulls data from two files data.txt and companion.txt, the latter being a optional file to add data to item.

What I learned today

  • txt files, used in this way, are very sensitive. Even though they contain html, the white space matters (unlike in html files).
  • In referencing a local subdirectory, it appears to be a good idea to begin with a leading slash

What I don’t know/ want to figure out

  • Now I want to think about what I really want to do with this sort of functionality, and then look for the best way to implement it. I currently think I would like to do the following types of things :
    • quotes: put up random quotes taken from a file of indefinite length
    • images with text: put up an image with a (sometimes extended) caption.
    • document with text: perhaps put up a link to a paper with a precis or abstract
  • Ideally in all cases I would have a directory for each thing that is randomly selected from; each item

Next Steps

  • I started looking into JavaScript (on w3schools, see notes) thinking it might be more straightforward, and certainly easier to test.

Views: 7