|
|
|
|
Thread title: Replace ); with a string |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
07-08-2007, 09:06 PM
|
#1
|
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
Posts: 542
|
Replace ); with a string
I am trying to use str_replace to replace ); with a string value.
users.php
PHP Code:
<?php
$users = array
(
"100000" => array ( "username" => "Seraskier" ),
);
register.php
PHP Code:
<?php include("users.php");
$fopen = fopen("users.php", "a+");
if ( $_GET['action'] == "register" )
{
$id = end(array_keys($users)) + 1;
$content = str_replace(");", $id, $users);
fwrite($fopen, $content."\n);");
}
echo "<form method='post' action='?action=register'><input type='submit' value='Register'></form>";
?>
basically add a user into the array...
to replace ); with the array of the user, then have the code put in a ); after its inserted...except its not working..
|
|
07-08-2007, 09:23 PM
|
#2
|
Status: Waving
Join date: Aug 2005
Location:
Expertise:
Software:
Posts: 2,694
|
I am certain there is a function for PHP that inserts data into arrays, not sure if it's those types of arrays, but just in general.
|
|
07-08-2007, 09:32 PM
|
#3
|
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
Posts: 542
|
yeah there is... but thats like temporary, im using this as a database...
|
|
07-09-2007, 02:14 AM
|
#4
|
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
Posts: 542
|
I have looked at fget, fread, and acouple more. I know it is possible but if someone could post up anything that would help, that would be great.
Thank You.
Jordan Martin
Seraskier
|
|
07-09-2007, 02:18 AM
|
#5
|
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
Posts: 6,894
|
As both methods are incredibly bad, your better using a text file as your database in the following format
----
Username
----
Username2
MD5 it if you dont want unauthorized access. Just explode ---- and you have yourself the array.
Why arent you using a mysql database? Or XML if you dont have a mysql database?
|
|
07-09-2007, 06:05 AM
|
#6
|
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
Posts: 542
|
As both methods are incredibly bad, your better using a text file as your database in the following format
|
id rather do it this way, I know that it is possible im just having trouble doing it.
MD5 it if you dont want unauthorized access. Just explode ---- and you have yourself the array.
|
I am going to password the file so it is unreadable to other people, depending on how i code it.
Why arent you using a mysql database? Or XML if you dont have a mysql database?
|
just trying something new
but if anybody can somehow help me out that would be great.
|
|
07-09-2007, 09:03 AM
|
#7
|
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
Posts: 1,078
|
What exactly is not working for you? You also need to close your file handle otherwise you're creating a memory leak.
I'm not so sure that you can include a file then attempt to write it in the same file. You can just read the users.php file into a variable then use www.php.net/eval to get the users variable.
For more help I'll need to know what exactly is not working for you.
|
|
07-09-2007, 03:01 PM
|
#8
|
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
Posts: 6,894
|
Originally Posted by Seraskier
just trying something new
|
If you are going to try something new, I suggest it be a good, let alone useful thing.
|
|
07-09-2007, 06:29 PM
|
#9
|
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
Posts: 542
|
Originally Posted by CreativeLogic
For more help I'll need to know what exactly is not working for you.
|
Putting another array before );
PHP Code:
<?php
$users = array
(
"100000" => array ( "username" => "Seraskier" ),
);
?>
basically, putting a new entry into the array before the );
|
|
07-09-2007, 06:36 PM
|
#10
|
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
Posts: 3,820
|
If you're looking for something simple, why not just save a serialized version of the array into the 'database' file (users.php). To use that, you'd just have to unserialize it and assign that value to a variable.
That makes more sense than playing around with file pointers and such like, to me at least. If you don't understand what I'm talking about, just ask.
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|