trying to create a script.. problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cabra
Forum Newbie
Posts: 1
Joined: Sun May 19, 2002 6:02 pm

trying to create a script.. problems

Post by cabra »

I'm making a script that adds about 6 lines of code to the .htaccess file. What the code in the .htaccess does is basically make sub domains with a cname and folder re-routing. Anyway, I have a login section where the admin logs in and is able to create a new sub by filling in some information. I've made that part of the script, and writes to the .htaccess fine. the problem i'm having is I don't know how to make a delete feature or edit feature, and i'm semi-new to php. I don't have MySQL access either. Can anyone help me?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

Basicly you're creating a textfile with a line for each sub no?

What I do in similar cases when using flat (text) files and I want to be able to delete and edit certain lines is not use a normal write command.

But what I do is use

Code: Select all

$file = file("thefile");
// to get the content of the file

$fileї$nr] = "";
// incase of delete and $nr being the line number of the line you want to delete.. or

$fileї$nr] = "$editedcontent";
// in case of edit of a certain line.

// then
$a1 = fopen("thefile", w+);
flock($a1,2);
foreach($file as $key){
fwrite ($a1, $key);
}
fclose($a1);
// to write all in the file

Basicly what you do is get all the content from the file as $file first... then alter those lines in the array $file so that they become what you want them to.

Once that's done you open the file with w+ which basicly removes everything from the file.
Then use a foreach loop to rewrite all the data in the $file array into the file... and this contains the edited data.

Basicly I've found that this works rather perfectly ;)

hope that helps
lc
ShrineMaster
Forum Newbie
Posts: 7
Joined: Mon May 20, 2002 5:33 am

Text Databases

Post by ShrineMaster »

If you don't have access to a database like MySQL, but you can have php writeable files/directories you can use text files as databases.

Check out this function, it'll help you get a start on a simple database.
fgetcsv()
http://www.php.net/manual/en/function.fgetcsv.php

I've used it on several of my own sites, works rather well for simple stuff.
Post Reply