Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Load array from file?

Featured Replies

I want to use a .txt file to store small amounts of data such as preferences set my the admin or other data. It would all be easy to represent in arrays with the option name as the key and the option set as the value. I want to use a simple format in the text file such as Key: Value on each line. How might I parse this properly as all the ways I have found in the functions list to load in a file to an array such as file() load it with integer keys and would put the whole line as the value. I want to specify the key and value in the file.

 

EDIT: its amazing how fast you can find an answer on your own once you ask someone else for it. it looks like what I want to do is use = as my delimiter and use the parse_ini_file function. Any additional advice would be great though if I'm overlooking anything.

you are describing something that basically replicates a table in a database - why not just use a database instead?

  • Author

mostly because I want it to all be together in one place. A database requires making calls to the database server and for tech illiterates is more difficult to back up because you then have to make a database backup too. If all the data is stored in files then the user can just copy the whole thing, data, content, and software together and save it to their computer as a backup.

 

Are there any major reasons not to do it this way instead of just using MySQL?

 

EDIT: would it cause a performance hit to do it this way?

btw, I also just discovered the JSON encode and decode functions which seem an even easier way of doing this.

I think it would be faster to do it in a MySQL database, but if for some reason you don't want to do that ... besides using json_encode/decode, you could also use serialize/unserialize (the output is similar with the JSON format).

 

L.E.: One advantage of using the database is that you can modify individual settings. By using an array of settings you'll have to permanently read and write the entire array.

  • Author

But which incurs more overhead? Keeping in mind that the arrays would be on the order of a half dozen to dozen key/value pairs. Also, in many cases, I foresee needing the whole array. ie, post data in a blog, id need the author, date, tag list, etc. rather often, not just one element.

I'd go with the database. These are not (admin) settings anymore.

I foresee needing the whole array. ie, post data in a blog, id need the author, date, tag list, etc. rather often, not just one element.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.