Jump to content

Recommended Posts

Made a simple script that can add, edit, or delete objects in a flat file. To use for news, simple ecom, etc. Created the script and tested in on one server and worked perfect. Just moved it to the actual server it will stay on and for some reason what used to make a new line for a new object just adds an upright looking rectangle looking symbol. Sorry can't copy it here cause it won't show up; will only show up in notepad. Once the symbol is added it will add the new data in the same line is the last object in the flat file. Anyone have any thoughts?!?!?!

 

This is what I'm using to write a new object and delete a new object.

 

To Add and object where "\n" should create a new line for a new object:

else if ($action == "add_item"){
// Add Item To File
$ai_data = "\n".$item_cat."|".$item_code."|".$item_name."|".$item_discription."|".$item_price."|".$item_urls."|".$item_urll;
$fj = fopen("data/items.txt","a");
fwrite($fj,$ai_data);
fclose($fj);
$whatdo = "go";

 

To Delete an object:

if ($action == "delete"){
// Delete Screen
unset ($items[$item_key]);
$fh = fopen("data/items.txt","w");
foreach ($items as $whats_left){
fwrite ($fh,$whats_left);
}
fclose ($fh);
$whatdo = "go";

 

My main goal it to have the new object appended to the other exsisting objects in a new line. That will solve all my issues.

Link to comment
https://forums.phpfreaks.com/topic/54601-new-line-in-a-flat-file/
Share on other sites

Notepad is bad to view server created files in. The box looking item is the new line character.

 

I suggest opening the document in Wordpad and see if you still get the same character. If you do report back, if you do not and the data displays on new lines that is just how notepad is.

 

Chances are the original test server was on a Windows machine and the new one is a Linux machine. Notepad is good with windows created documents, but does not handle the unix ones correctly.

You were correct! I opened the txt file in wordpad and there was no upright rectangle symbol and the new object was on a new line. Thats cool however when the object is delete the symbol stays and gives me a blank object as there's still a new line with no data.  I have tried ltrim \n and trim on my delete function and didn't remove the symbol.  Maybe I had the trim in the wrong place?!?!?!

 

Had it like this:

if ($action == "delete"){
// Delete Screen
unset ($items[$item_key]);
$fh = fopen("data/items.txt","w");
foreach ($items as $whats_left){
trim ($whats_left,"\n");
fwrite ($fh,$whats_left);
}
fclose ($fh);
$whatdo = "go";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.