How to delete line after a time lapse?

I have created some PHP coding that allows a user to place a href link into a file but I want the line to delete after a specific time lapse.

Has anybody any ideas?

I have studied
but that deletes a file. I only want the line deleted.

I have also studied
but I prefer the deleteLine coding to be in the same line as the href so that a file name & line number will not be necessary. Plus there appears no timeframe in that coding.

It is not a row in a database that I want deleted. It is a line in a .php file I want deleted.

Do you want to remove the display after so many minutes or after a certain date and time?
One would be when you display the link from the database, you would check a stored date/time and hide it if pass the limit. The other, you would need to use a JQuery routine to delay so many seconds or minutes and then remove the link from the page. Really depends what you want done !

Update 11/9/2021
In my text editor, UltraEdit I just need to press Ctrl+E to delete a whole line & its contents. I want something similar in PHP.

You can’t delete a line per se - you’d need to overwrite the file with the new contents. A quick way would be to use file_get_contents to load the file as a string; delete the line from this string using str_replace; then save the file again using file_put_contents.

OK thanks @skawid, on the face of it, it appears to be too complicated. The file is likely to have many lines from various users linking their adverts. When each advert display runs its time we want the link to automatically delete, and also the user to be able to delete the link. The advert itself will at all times remain untouched & unaffected.

Can you think of any other simple resolution?

Yes, we can! Use a database as you should be using. Nobody uses text files for posts from users.
It is just to cluttered and hard to edit. And, text is the worst thing for a server. It’s the slowest processing
part of a server. A database would be the way to go. Easy to maintain the entries.

Why are you using text files?

Thanks @ErnieAlex. Firstly, I am self taught from the Internet. I even relocated to a different country for the purpose of learning web development but found too many unreliable people claiming to be experts, so I then decided the only way to get the job done properly was to do it myself.

I do use a database for the initial registration. I was advised early in the learning process not to load photos into the database because of clogging & then I reached the conclusion that a database is a series of text files that can be interrelated with each other, so only use it for that purpose. That answers your last sentence.

From your advice I now need to learn the database process. Can you guide me in the right direction? I only need basic advice.

I did have the idea of creating a macro system, similar to that found in UltraEdit, & place it into a user library within CodeIgniter, so that there would be no limitations. UltraEdit’s macro system has very little limitation, if any. But that would only operate with text files, I doubt if it could operate within a database, but maybe for database entries.

Well, there are hundreds of question now. But, let’s explain some basic things. Databases run in C or C++ and are extremely fast. If you were to write your text processing in C then, yes, it will run fast enough to put onto a webpage. But, you would need to wrap it up in odd libraries to get it all to work correctly. A ton of work when PHP is designed to do all of this work, for you.

Next, database code is extremely fast if the database is designed correctly. For simple posts, it is extremely flexible and very fast. That is why every huge website in the world uses it. Connecting to a database is easy, just a couple lines of code, reading, storing, updating and deleting data is easy to handle. The only tricky part is to layout your needs for data first and design the database tables to work best for your useage. I suggest leaning PDO since it is the most secure. It is basically an advanced version of MySQLi. If you use PDO and “prepared statements”, your site will be quite secure from hackers. Also, you need to design the database tables so that they interact with each other. For example, if you have users in one table and posts in another, you can link them together using DB-Join’s. In a query, you can join two tables to make the search for data faster. Such as finding all of the latest posts for one user or all of the latest posts for all users. Simple queries.

Now with that said, think of a database a a spreadsheet. It simply has pages ( tables ), rows of data and columns of fields. Simple. And, you create a name for each field and a name for each table. All “data” needed for users would, of course, be saved in a table named “users” or “members”. All posts could be saved in a table called posts. Simple enough. In the posts table, you would have one field called, let’s say “owner_id” or “poster_id” and that links them back to the users table. So, in one simple joined query, you can pull out all the details of any user along with all of their posts. For programming systems, you might want to have users, program_snipit’s or whatever…

A site that has a ton of general information is here: On the top, you can select the language you want details about and on the left a subject inside of that language. It has PHP, CSS, HTML and PDO to get you started. The code they show there is not always the best, but, it will get you started nicely. Also, if you want to learn how to use PDO, you should read this PDF:

But, I suggest you first make a list of all the data or info you wish to save. Figure out what tables the data needs to be in. Do not duplicate data at all. Make a list of tables and fields needed and how each table will work with the others. Then, have the group here review it. We have a large number of expert programmers here and can give you solid input on your design. If it is something private, you can private-message some of use to ask for private help. But, in general we do not care what you are creating, but, we want to help you with the code. Yes, it’s ALL ABOUT THE CODE ! Ha! Hope this helps get you started !

Thanks @ErnieAlex. Well Im confused. Im planning on building the best website on the Internet. Under my current process Im guessing it should be online in less than 6 months, & bearing in mind that it is almost 10 years since I relocated. Even under my current process it is envisaged to bring about fundamental change in 6-12 months after launch. Im tending to think that it will be best at that time to incorporate the database as you suggest. At that time there will be an established database of registered users, some being web developers & participating in the websites ongoing development, and after the change will begin to be rewarded for their contribution.

If you would like to know more you can contact me at bensanchez480 [at] yahoo dot com dot ph

The current best website on the internet used a real database from the start. If you want to match them you should do the same thing.

Sponsor our Newsletter | Privacy Policy | Terms of Service