More work on Flipcards with GPT

28 April 2024

When doing this development, remember the following:

  1. Refresh the File Manager page on my site
  2. Go into the web developer tool on firefox and reload the page — this is not always ncessary.
  3. One approach to circumvent 2 is to just append a date to the file being tested so that it is always diffrent.

When weird things happen

  • Make sure I haven’t overwritten </td> or </tr> etc tags
  • Make sure character encodings are consistent
  • Make sure GPT hasn’t changed the names of .js or .php files and functions.
  • Make sure caching is not causing problems… — for instance Javascript can cache ajax requests. One way around this is :

    Cache Prevention: Appended a timestamp query parameter (nocache) to the URL in the fetch request to ensure the browser fetches a new response each time without caching the result.

TO DO

  • At some point I need to figure out the reasons for using different encodings, determine what is best (i.e. the norm), and make sure all my pages are consistent.

Web Development

It has been ages since I’ve done anything, but I’m back.

I’m trying to implement a new version of flashcards.

Something strange is happening — it is a huge struggle to get… Firefox? My web platform?… to actually run new files I am uploading. It is some kind of cache or memory problem. It may be complicated by caches acting differently for html, php, javascript, etc.???

I think I have finally determined that if I open the page that I’ve changed in Firefox, go into to Browser Tools and choose Web Developer Tools and then hit refresh, the new changes will take effect.

That appears to work, but is cumbersome.

There should be a way to turn off caching altogether. I tried doing that, but it didn’t appear to work — I’m not sure if it turns it off at all, or only for particular windows in the browser, or what.

I think I may just need to step back and do a tutorial on web development… either that or figure out how to do development on MAMP, which I I think I had figured out a couple of years ago, but have now forgotten.

Yuck.


Next day. To ensure I have the latest code actually running I must:

  1. Refresh the File Manager page on my site
  2. Go into the web developer tool on firefox and reload the page.

It is not always necessary to do both or even either of these.

Entering text and saving it to a server file

Saturday 30 April 2022

What I would like to do today is to be able to enter text on a web page and have it entered into a server file. That is complicated by the need to validate the entry so a page can’t be hacked. Yesterday, or maybe it was the day before, I think I figure out in general what I needed to do, and even wrote/found code snippets to do it. Today I want to try it and see if it works.

First, I need to remember how to get MAMP running, so I can do the trial and error on my local machine. OK, that is just a matter of finding
1. MAMP (which is in my applications launch page), and
2. the MAMP htdocs directory (there’s a shortcut in my favorites panel)
OK, so I can launch index, and I can see it is running on local host (and I have a note on that instance of the index that says “MAMP” as a double check), so that is good, Clicking on subsidiary pages works fine, and they too run on local host.

BUT when I click on the .php link firefox wants to open the file with something else, rather than run the page.
…I thought this was working before.
OK, looks like I left workspace.php in a non-working form.
…but restoring the original doesn’t work. It still opens in BBEdit rather than running.
…I thought that I had this working.
Ug.

Back to File Handling

Wednesday 27 April 2022

When I last wrote I was focused on trying to create an exercise tracking list with checkboxes for my workspace page. Since then I’ve decided it is easier and more useful to just use a spreadsheet, and so I did that and got distracted entirely from web programming by my physical therapy, etc., regime.

Now I want to take up programming again. I would like to return to the file-handling material again, so that I can enter text into a file (e.g., like my quotations file) from a web page. I would like to be able to do the following

  • Flashcards.
    Get flashcards working, drawing material from a file, and be able to create new flashcards by adding text to a file from the web page
  • Quotations. These now randomly select lines from a file.
    I would also like to be able to add new quotations by typing an entry into the web page, rather than editing a copy of the file on my mac and then uploading it.
  • For both of the above I would like to be able to add some state variables so that I can suppress an item, or cause it to show up more frequently (e.g., by clicking a button).

Getting Text Input with Forms

OK, I can get input like this:

<form action="/action_page.php">
  <label for="TextInput">Quotation</label><br>
  <input type="text" id="TextInput" name="TextInput"<br><br>
  <input type="submit" value="Submit">
</form> 

This passes an input “XXX” to “action_page.php” as TextInput=XXX.
That’s nice, but what I want to do is get that text into a file, presumably appended to a file.

OK, let’s try this again. Here’s code that gets the input

<html>
<body>

<form action="WriteToFile_get.php" method="get">
Quotation: <input type="text" name="EnteredQuotation"><br>
<input type="submit">
</form>

</body>
</html>

and then we have a WriteToFile_get.php file that is:

<html>
<body>

<?php echo $_GET["EnteredQuotation"]; ?><br>

</body>
</html>

I think, in the above two blocks, all instances of “get” could be changed to “post”

In either case, my working hypothesis is that $_GET[“<name value>”] will contain the entered data and should be able to be appended to a file.

So WritetoFile.php should be:

<html>
<body>

<?php echo $_GET["EnteredQuotation"]; ?><br>


<? php
$fh = fopen(“quotations.txt”, ‘a’) or die(“Failed to create text file.”);
fwrite($fh,$_GET["EnteredQuotation") or die(“Could not write to file.”);
fclose($fh);
echo “File ‘quotations.txt’ written successfully.”;
?>

</body>
</html>

OK, let’s modify this to (1) use PUT, (2) use validation. And once this is working, change the type from text to textarea (which apparently doesn’t require the “input” command, i.e.: <textarea name=”EnteredQuotation” rows=”5″ cols=”40″></textarea>

<html>
<body>

<form action="WriteToFile_get.php" method="post">
Quotation: <input type="text" name="EnteredQuotation"><br>
<input type="submit">
</form>

</body>
</html>

AND the WriteToFile.php page will be

<html>
<body>

<?php echo $_PUT["EnteredQuotation"]; ?><br>

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $EnteredQuotation = test_input($_POST["EnteredQuotation"]);
 }

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$fh = fopen(“quotations.txt”, ‘a’) or die(“Failed to create text file.”);
fwrite($fh,$_GET["EnteredQuotation") or die(“Could not write to file.”);
fclose($fh);
echo “File ‘quotations.txt’ written successfully.”;
?>

</body>
</html>


?>

File handling via php

Tuesday `10 March 2022

What I want to do

The current goal is to be able to input something on the web page, save it to a file, and get it back.

  • An example of what I’d like to do is log my exercise over the course of the day, save it, and the be able to get it back during the day, and also, later on, as history.
  • It could also be nice to be able to update the quotations.text file directly from the web page, rather than editing it and uploading a new version.

…I looked into cookies, and it does not appear that they provide the functionality that I want; or, if they do, it seems like working with a regular txt file would provide more flexibility. In the long run, probably a database would be best, but I will save that for later.

So, more particularly, I want to

Open a file
Read one or more lines
One of the following
Display the contents of the file on the page & then alter it

Add a line to the file
delete a line from the file
Write the resulting data to the file, replacing the altered material

File Handling

I will begin by looking at the Robin Nixon book, p 147

<? php
$fh = fopen(“x_logfile.txt”, ‘w’) or die(“Failed to create text file.”);

$text = “This is one line of text…”;

//$text = <<<_END //programmatically add text to a file? Didn’t work.
// line 1
// line 2
// line 3
// _END;

fwrite($fh, $text) or die(“Could not write to file.”);
fclose($fh);
echo “File ‘x_logfile.txt’ written successfully.”;
?>

So far

  • This gives me fopen, fwrite, and fclose. fopen creates a file handle which subsequent file functions use. fopen can also take various arguments which put constraints on what may be done to the opened file (e.g., read only, write only, append only).
    • I tried a, and that works as advertised: it appends text to the end of the file without zeroing the existing file.
  • The “or die()” part in the first line is not obvious to me. Presumably if fopen() is true, then the second part is never evaluated and the program is terminated… that seems a bit sloppy to me.
  • The <<<_END bit of code did not work; when I commented it out and replaced it with just assigning a string to $text all was well — since the latter is more what I will need, I will not worry about <<<
  • There is also a function file_exists(“filename”) that returns a boolean
  • And there is a function fseek($filehandle, positions-to-move-pointer-back, location), where location SEEK_END is the end of the file.
  • And there are lots of other functions that I won’t need, or at least not yet: these include flock() for locking and unlocking files, and file_get_contents() for getting the entire content of a file

Grrr.

  • Forgetting a single semicolon can cause the entire program to fail (i.e. do nothing).
  • And using <? php rather than <?php can do the same
  • And putting \n outside double quotes can do the same
  • echo does not display newlines unless you first have the statement: echo “<pre>”;

VSC seems to offer the potential to validate php code, which might catch such errors, except that it wants me to tell it where the php executable is, and I don’t know that. There are all sorts of php files in the MAMP directory/subdirectories. Sigh.

OK, anyway, the php filehandling works. The next step is to figure out how to get input from the user via the web page. This will be complicated by the fact that to be secure we will want to validate that whatever is entered is not an attack…

Validating/Sanitizing Input

  • If you are uploading a file, then there are ways you can check to make sure that the file is one of a few expected types.
  • If you’ve got a string, you can do some things to ‘sanitize’ the input
    • $name = strtolower(preg_replace("[^A-Za-z0-9.]", "",$name));
    • This command creates a lowercase-only string containing alphanumeric characters or periods.

On to Forms

I think what I need to look at next is forms. Forms seem to be the way of getting user input from a web page. That makes sense, as it would control the nature of the input so security is less of an issue, except when the user is allowed to enter a text field.

<form action="/script-that-processes-form-entries.php">
  <label for="ID-of-the-input-field">First name:</label><br>
  <input type="type-of-the=input" id="ID-of-the-input-field" 
          name="variable-with-content-passed-to-script" 
          value="default-value"><br><br>
  <input type="submit" value="Submit">
</form> 

note that the value of “for” in the label must match the ID of an input

form takes three arguments:

  • action — typically a the location/name of a script that processes the form data
  • target (where the results of the action are displayed) — e.g., _self, or _blank
  • method, get or post. The former passes variables as part of a URL (non-secure, limited to 2048 characters, but good if the user is going to bookmark the result; the latter does something internal that keeps the submitted values invisible and has no length limits.
  • autocomplete (can be on or off, default is off)
  • novalidate (boolean; true if present — default is false)

Where I’m stopping

  • I have a prototype of a form for getting exercise data on the workspace page in MAMP
  • I am breaking the model a bit, because I want to be able to check multiple checkboxes for a single entry — but I don’t think this should be a problem with what I’m doing now.
  • In any event, I can see that the data is getting into the form, by using “get” to pass the parameters embedded into a URL
Kegel exercises (slow & fast): _ _ _ _ _ _

Walking (miles):_

Running (miles):_

Eccentric Heel Lifts: _ _ _ _ _ _

Where I’m stuck

  • I am trying to figure out how to gather or otherwise access the data entered into the form so that I can save it to the log file.
  • I found a bit of javascript the purports to read the form data into variables, but I can’t tell if it is working (that is here: https://discover.hubpages.com/technology/Retrieving-HTML-Form-Data-Using-JavaScritp)
  • The problem might be that I don’t understand the model of when an embedded java script runs, and so it is not running and I’m not seeing the results or it is running but I don’t know where to look for the results
  • Or the javascript just might not be working because the tutorial is wrong or I did something wrong… –

What Next

I should be able to find an example of getting input from a form, saving it, and then retrieving it to repopulat the form. Some pages to check out:

https://www.w3schools.com/php/php_form_complete.asp

https://www.ostraining.com/blog/coding/retrieve-html-form-data-with-php/

Tracking exercises, &c

Wednesday 2 March 2022

  • Found code to put a set of checkboxes into my workspace, so that I can flexibly keep track of exercises, etc.
  • Currently it does not save state between page refreshes: that seems like it ought to be doable with a database or cookie or something.
  • Next, once that is done, it would be nice to be able to have not just a check box, but also a textbook so that, for example, mileage could be put into an entry.
  • After that, it would also be nice to be able to view a history of activity — initially as a table, but then perhaps in some fancier ways.
  • Finally, it would be nice to be able to add (and delete) activities as they change — this would, of course, complicate creating a graphical display….

VSC, Github Desktop, css-in-wordpress

Friday 25 February 2022

At the end of the day, I am

  • Able to use VSC, and find it preferable to BBEdit
  • I got github desktop to let me edit a branch, but I couldn’t see how to merge it back in to main. I don’t really understand the git model yet. I finally got rid of the branch, and manually updated the main files, and uploaded them.
  • I’ve figured out markup (as it works in wordpress), and figured out how to change the appearance of headers in my wordpress theme.

All in all a reasonable day’s work.

VSC

I’ve installed Visual Studio Code on my Mac. So far it is performing as promised — it makes css code more legible, and shows examples of colors referred to in the text. Hopefully it will work as well for php and html. Taking a quick peek at the html reminded me that there is still a lot of clean up to do. …Before I embark on that, I want to see if I can get git or github working locally; modern version control would certainly be preferrable to my modus operandi of just creating copies of folders and trying to name the appropriately.

Github Desktop

I looked into Github and discovered that I have an account, with the username 2goldfinch, from 2017. This was created for some kind of IBM project, but I never used it other than making a couple of test repositories. Now I hope to explore it a bit more, and am encouraged that there is a desktop version that is oriented towards point and click folks like me. …Besides using it to maintain my website materials, I’ve read that people also use it to manage writing. I’m not entirely sure how that works — do I need to write plain text with markdown? We shall see.

Markdown and css-in-wordpress

So the basic markdown works for creating headings, but I don’t see how to re-use reusable blocks; applying custom css styles to each block seems way to cumbersome to be the way it ought to work.

Also, all of a sudden, I am now getting the spinning beachball cursor appearing forlongish amounts of time as I am writing here. That doesn’t seem good. Could it be related to special css files? …Or is it some weird interaction with githum desktop trying to sign into github.com. Not sure.

=> Not long after, github desktop complained it wasn’t in the app folder and that this might cause problems. So I moved it, and also moved VSC to the app folder. Hopefully that will help. ….That, and a reboot, seemed to help.

Changing the appearance of the headers with css

OK, now I can use markdown to easily create headers, and I’ve found out how to insert css to change the appearance of the header text — it appears necessary to include “!important” at the end of each css statement. I presume that overrules defaults set elsewhere.

h1 {
    color: #000066 !important;
	font: small-caps bold 20pt Arial, sans-serif !important;
}

h1.entry-title {
    color: black !important;
	font:  bold 24pt Arial, sans-serif !important;
}

h2 {
    color: darkred !important;
	font: small-caps bold 16pt Arial, sans-serif !important;

}

h3 {
    color: cornflowerblue !important;
	font: bold 13pt Arial, sans-serif !important;

}

Markdown; Next: Git & Visual Studio Code

Thursday, 24 February 2022

Markdown

OK, it looks like this wordpress editor automatically interprets *Markdown*… at least I think it does. **Sometimes.** Well, maybe only for headings? Or things that are on their own lines?

Things I can do

  • create headers with # or ## or ### …
  • create a block quote with >
  • create a list with * or 1, and indent it with a space
  • create inline code using back single quotes` (NB. the backquotes behave oddly, but work)
  • create a horizontal rule using —

Things I can’t do

  • create inline emphasis using asterixes
  • create inline highlights using =’s
  • create inline code using back single quotes
  • create a horizontal rule using ###
  • create a link using this syntax: [a link to my site](https://tomeri.org)

But let’s make sure the things I think I can’t do are not showing up when published

  • create *inline* **emphasis** using ***asterixes***
  • create inline ==highlights== using =’s
  • create a link using this syntax: [a link to my site](https://tomeri.org)

Things I’d like to be able to do

  • Create my own .css styles. I can see where to plug in the style names on the left, but where do I define the css styles?

Next Thing

The next thing I want to do is to learn more about git and how it is used for version control. In particular, there are people who use git for non-coding tasks, such as writing, so I’d like to see if that makes sense

After that, Jeffrey recommended I look at Visual Studio from Microsoft which could prove very helpful in (1) detecting errors, and (2) suggesting what code to write. He gave me a demo where he wrote a comment about what the code was going to do, and the editor supplied the actual code (by doing matching from within github).

MAMP

Wednesday 23 February 2022

A couple of weeks ago I installed MAMP. MAMP is a solution stack for web development and stands for Macintosh (OS), Apache , MySQL, PHP. It enables one to run a server based environment on a local machine, and simplifies development because new versions of a site that use php do not have to be uploaded to an external server.

I am now going back to MAMP for php development — that will help avoid the error I had yesterday where I uploaded my php file to the wrong directory and was unable to see any effect of changes I make. With MAMP, I can just edit the file directly.

Figuring out the code

The first thing I will do is figure out the code that makes the random quotations work. Here is the snippet:

<?php

$textfile = 'quotations.txt'; # data file of text lines to display randomly (html ok)

#### READ STRINGS FROM FILE (in same directory) INTO AN ARRAY AND RANDOMIZE THEM
ini_set('auto_detect_line_endings', TRUE);      #alters php settings to detect newlines
$disp = file($textfile, FILE_IGNORE_NEW_LINES); #reads a file into an array
$count = (count($disp)-1);                      #number of lines in array minus 1
$rand = array();                                # declare that rand is an array
for ($a=0;$a<=$count;$a++)                         
    {array_push($rand,$a);}                     # Puts sequence of $count indices into $rand
shuffle($rand);                                 # shuffles indices in $rand

#####Create html formatting and embed choosen string in it
echo '<table id="foo">';
$col_ent = array();                             # declare that $col_ent is an array

$i = 0;
 $key = $rand[$i];                               #put the first element of $rand into $key
 array_push($col_ent,'1');                       #put 1 into #col_ent
echo "<tr><td class='foo-$i'>";

echo "<div class=\"quotationDiv\">";
/* style=\"margin: 10% 15%; text-align: center; font-size:18pt; font-weight:bold;\">"; */
echo "$disp[$key]";  /* the string*/            #display a random string using $key
echo '</div></td></tr></table>';

#Once there was more code that created multiple random entries indexed with col_ent

/*
echo $post;
*/

?>


Ok, I’ve commented the above, and can see that the original code that I copied from this had a lot of leftovers from when it tried to be a far more general function. I think I should be able to rewrite the above so I can just generate a random number and use it as an index to select a random line.

Like this

  • #load the file into the array
  • #determine the length of the array
  • #generate a random index from the set 0 to length-1
    (assuming that php arrays start with 0)
  • #print out the line, embedded in the proper html

That works. The reduced code looks like this:

<?php

$textfile = 'quotations.txt'; # data file of text lines to display randomly (html ok)

#### READ STRINGS FROM FILE (in same directory) INTO AN ARRAY AND RANDOMIZE THEM
ini_set('auto_detect_line_endings', TRUE);      #alters php settings
$quotes = file($textfile, FILE_IGNORE_NEW_LINES);#reads a file into an array
$count = (count($quotes)-1);                     #count number of lines and sub 1
$key=rand(0,$count);                             #generate a random index 

#####Create html formatting and embed choosen string in it
echo '<table id="foo">';

$i = 0;
echo "<tr><td class='foo-$i'>";

echo "<div class=\"quotationDiv\">";
/* style=\"margin: 10% 15%; text-align: center; font-size:18pt; font-weight:bold;\">"; */
echo "$quotes[$key]";  /* the string*/            #display a random string using $key
echo '</div></td></tr></table>';

#Once there was more code that created multiple random entries indexed with col_ent

?>
  • Now I need to remove the legacy formatting… the<td class=’foo-$i’>.
  • And I also need to be crisper on the IDs and class stuff…
  • and the div and table stuff
  • OK, legacy formatting is gone — the table formatting has been discarded and there is just Div.
  • One odd thing that is happening is when I make tweaks to the .php file, they don’t always seem to have an effect right away. It’s as though the original file is cached, though doing what I think is required to force a reload doesn’t make a difference
  • ==> The above problem appears to be due to having ‘lost’ a semi colon in the style section.

The other mystery is that I tried putting all the style code into the main css file and it broke stuff — could that be due to the missing semi-colon???

=> YES
==> ALSO, NEED TO BE CAREFUL TO FORCE A REFRESH OF THE UPLOADED FILES

Random Flip Cards from File

Tuesday 22 February 2022

Where I am

I am now modifying the php code to make it work for flip cards

  1. first I simplified the old code by taking out various state variables. So the resulting code will assume a file is in the same directory, and not have options for giving it titles or putting things before or after.
  2. I should also go ahead and take out the code that allows multiple random items to be put up — but I don’t understand the code well enough yet. I will defer that until I get the basic things I want working
  3. What I will try next is to just get text from a line of a file onto one side of the card
  4. Then I will try parsing the line, so I can get stuff on the front and back.
  5. then we’ll see…

Next Steps

At this point I’ve gotten stuck on #3. So I am going to go back to #2, simply the code as much as possible, and make sure I understand everything that it is doing. Then I will return to #3.

  • Repeated an earlier error: uploaded a file to the wrong directory, and spent nearly an hour trying things and not getting any result — so always make sure that I can see a change when I upload a file.

Mo: Quick Flipcard

21 February 2022

Spent about an hour finding some css/html to make a flip card for a page. I still need to fully understand how it works. One that is done, I hope to be able to modify my php quote code so that I can pull the front and back of textual flipcards from a file and display a random card…

Fr: Omeka; other

Omeka

  • Omeka is working well enough, but when I display a single item it just lists all the Dublin Core meta-data — I would like to have more control over what is shown. It is possible that there are other ways to achieve that: there are entities called “Exhibits” and (I think) Pages that may allow for it.
  • What I would like, I think, is the ability to display several pictures at once, with text relating them — for example, Olivine in basaltic scoria, weather/altered and fresh, as well as green (olvine) sand.

We: Flashcards & Omeka

16 February 2022

Omeka

  • After the flashcard exploration did not work out, I decided to see if there were any pre-made tools offered by softaculous. And indeed there were: in particulr, Omeka, which is an open source platform for creating exhibits.
  • I managed to set it up on my site, and am currently importing a few pictures of rock samples into my site. So far, so good!

Flashcards

  • I found some code that is supposed to produce flashcards using html, javascript and jquery.

But it doesn’t entirely work. …I didn’t think to test it until I’d gone through the tutorial and produced something that didn’t quite work.

  • Then I just downloaded the original source, and that didn’t work either.
  • I tried it online, in case there was some problem with running it locally, but that didn’t help.
  • Also looks like the format of the coding log isn’t working as I would wish. : – (

Mo: Website work

14 February 2022

What I’ve done so far

  • Refactored my blogs: one semi-private, one public
  • Decided to try keeping track of my coding notes via a blog
  • Playing around with using a menu in a wordpress blog

What I’ve learned

  • Can’t access local files from a web page for security reasons

Thoughts / What’s Next

  • Put up things I’m trying to learn — perhaps a template that provides flash card like functionality.

# # #

Sa: Site formatting changes; indenting images; style sheet import error

12 February 2022

What I did

I did not take notes.

I messed around with the formatting of the site, and made several minor changes

  • A banner describing the purpose of each page at the top
  • Elimination of the archive tap, and an incorporation of its content into the professional page
  • elimination of the borders around the innter tables on the professional page
  • fixing the left indent on pictures on the professional page

What I learned

  • I got a bit more confident with the style sheet
  • I figured out that to indent the images, I needed to use padding-right rather than margin-right (but I don’t know why – perhaps because it wasn’t with in a <p> tag?)
  • I had a lot of difficulty at first because my pages were reading in a previous version of the style sheet, so my changes to the new style sheet seemed to have no effect

What to do next

I would like to put up more content. Possibilities, all of which I want to pursue, are

  • book summaries
  • another essay
  • Information about rock specimens – which means I need to figure out a format…
  • The rock sample format also would, I think, allow me to embed things I want to work on learning

Also I need to clean up the various blogs – I should have only two blogs on the site. One for personal work, and one for publication.

Tu: New site version up; next step

Starting Point

About a week ago, before I went to Mayos, I did 1-3 above, and it didn’t work. First, nothing happened, and then I realized I was having trouble with the cache. I cleared the cache on Chrome, and things worked better, but the top horizontal menu was broken.

  • One theory is that somehow having a php page mixed in broke things.
  • Another theory is that there is a second cache on my server page, and maybe it is pulling from that; however, at the time, I was reluctant to delete that in case it broke everything and I’d be left with a dead site.

Current steps

I am trying a more cautious incremental approach. I have

1. Made sure that none of the top level pages (except index.html) have the same names as the original site

2. I have eliminated all references to .php files from this version

Results

It worked!

There was something wrong with the way I had included the .css file – it worked when the browser was reading files from the disk, but failed on the server.

I will now go back and try putting in the version with the php work.  Yes, that worked as well. The php file was not a problem.

Next steps

  • I am going to see if I can make the professional page look better by moving the images into the ‘content’ part of the screen grid.  I got the format the way I like it by putting a table within a table, but I need to figure out how to create and invoke a second table definition in the .css sheet so I can have an internal table with no borders. I ought to understand this.
  • Next I think I will print out the top pages, and edit the text for brevity.
  • After that I will return to php – it would be nice to put cool pictures up, with commentary, in the same way the quotes come up. This is probably a larger project, though.

Su: php random quotes working

Starting Point

At this point I have

  • Got the html mostly to where I want it
  •   I would still like to turn a few of the multi-file html documents into pdf versions so there are fewer files
  • I’ve gotten the php for the random quotes (mostly) the way I want it: I’ve slimmed down the code, embedded it in a workspace.php page (so I’ve learned I can mix a php page among my top level site pages, and can keep index.html)
  • there’s an internal border I’d like to get rid of, and for some reason the icon at the bottom of the .php page is not centering … but it doesn’t have to be there
  • I’ve created a new set of files in a staging directory.

Next steps

1. backup the current files on the server

2. create a fresh new set of files for my site 3. and make sure it works

We: Getting Random Quotes to work; errors

19-20 January 2022

Starting Point

I decided I would focus on getting quotes to work as I want them

I did two things first

  • – I mucked about, getting the formatting of the quotes the way I want it
  • And I put the formatting code in the php file, so that the file of quotes can just be text.

That worked well enough

Difficulties, Confusion, and Saving Bits that work

Then I decided I would try to unembed the formatting from the php file. That didn’t work out so well:

  • – I tried having the php just print out formatting that would rely on a css style either pulled from the .css file, or put in the head area in the style definition. Neither of those worked, but I’m not sure why. When I tried running this, the browser complained that it couldn’t load the .css file… perhaps because the browser won’t process a .php file that way? I’m not sure, but at this point I’m getting confused by my experiments, so I’m going to fall back to the last thing that worked, and record that.

And that was having the .php print out the formatting I want just before printing out the item using the randy script. The relevant bit of code looks like this:

echo "<td class='randy-$i'>";
    
   echo "<div style=\"margin: 10% 15%; text-align: center; font-size:24pt; 
         font-weight:bold; background-color:lightblue;\">";
    echo $infix.$disp[$key].$infix;
      if ($companion != '')
      {
      echo '</td>';
      echo "<td class='randy-companion-$i'>";
      echo $infix.$codata[$key].$infix;
      }
    $i++;
    echo '</td>';

So, this gets the code out of text file, and into a single line.

I would like to get it either into an external style sheet, or between style tags in the header.

I would like to get it either into an external style sheet, or between style tags in the header.
•	It may just be a matter of using an index.php file – that appears to access the style sheet, unlike putting the reference to the style sheet in something else. In that case, I do need to figure out how to do internal references to what used to be index.html. I wonder if there is a way to just reference the root file. 
•	I wrote the following line -- echo "<div class=\"quoteDiv\">"; -- but now realize that it probably will cause problems inside at <td> </td>:
•	And I wrote this for a stylesheet:
.BigQuote {
  background-color: lightGray;
  color: black;
  margin: 10% 25%;
  font-size:50px;
} 
And this for an in-html style:
<style>
.bigQuote {
margin: 10% 15%; 
text-align: center; 
font-size:24pt; 
font-weight:bold; 
background-color:lightblue;
}

The class=”active” line in the index.html:   <li><a class="active" href="index.html"><font size="+2">
references the following in the .css file:
.active {
  background-color: #82A3FF; 
  /*  #add8e6 -- aka cornflowerblue */
}
but I’m not sure if this will work because “active” is some kind of special state. 

I’m not sure how to reference the settings that are all part of a style tag. Maybe p.bigQuote? Can I put these things – properites or attributes or whatever inside a <p> element? 

Currently

  • randy1.php works and does latest version of formatting, by putting all formatting in a single line of the php file
  • randy2.php does not work
  • randy3.php works, and references div class=”quoteDiv”, but I can’t find where quoteDiv is defined

Success and Learnings

It’s easy to break things in php

  • It is very easy to ‘break’ a php file by messing up the formatting of an echo statement – leave a ; off and everything breaks with no error messages
  • For echo: Stuff in single quotes is not evaluated; stuff in double quotes is. Backslash can quote a character
  • echo $infix.$disp[$key].$infix; — I don’t understand what is going on here… are the dots connecting? Yes, it is a shorthand for echoing each variable in a different statement.      

randymin1 works

Ok, now I’ve made it to randy1min.php, which does the very simple thing of reading lines from a file into an array, randomizing the array, and displaying the first line. It would be more minimalist if I could determine the number of lines in the file, and read a single random line out of the file – but underneath the hood that might be not be any more efficient. 

#### READ STRINGS FROM FILE INTO AN ARRAY AND RANDOMIZE THEM
ini_set('auto_detect_line_endings', TRUE);
$file = $dpath.$textfile;
$disp = file($textfile, FILE_IGNORE_NEW_LINES);
$count = (count($disp)-1);
$rand = array();
for ($a=0;$a<=$count;$a++) {array_push($rand,$a);} shuffle($rand); # Creates an array of keys then shuffles them

#####Create html formatting and embed choosen string in it
echo '<table id="randy">';
$col_ent = array();
$i = 0;
 $key = $rand[$i];
 array_push($col_ent,'1');
echo "<tr><td class='randy-$i'>";
echo "<div style=\"margin: 10% 15%; text-align: center; font-size:12; font-weight:bold; background-color:lightblue;\">";
echo "$disp[$key]";  /* the string*/
echo '</div></td></tr></table>';

And that works. But I still don’t understand where div.quoteDiv is being defined… I clearly did that at some point, but where is it???? I want to change it!

Next Steps

Get the php-generated html working with style sheets

  • I’d like to figure out what is going on with the <div class=\”quoteDiv\”>”
  • I’d also like to figure out how to make html code generated by a php file use the style sheet – it seems like it should just happen automatically, but I’m not sure that’s the case.

•               

Integration into the site

  • Once I get the random quote display working, I want to
  • Figure out how to make it part of the html site (that probably means using an index.php file as my root, which in turn means I need to figure out how to link to that internally.  I think I have to build index.php links into the menu to get back to the home page…

Random Image Display

  • After quote stuff is integrated and working, I want to do the same thing for image files, mostly likely pulling caption text in to supplement each one.
  • Then, I’m thinking I will
    • find a way to have links to my experimental blogs on my sight, but keep them mostly hidden
    • decide if I feel like I have enough material to start a public blogMy hope is that having a place to ‘publicly’ display stuff I care about will motivate me to document it, and wrap it up in nice packages that will be useful for me later.

Notes

  • randy1.php and randy3.php both work; they differ only in that 3 uses <div class=\”quoteDiv\”>”  rather than inline html.
  • randy1min.php and randy3min.php are stripped down versions of the above; they have all of the general stuff I don’t need stripped out of them; they differ only as their parent files do.