MiniMonty Posted October 12, 2009 Share Posted October 12, 2009 Hi all, Trying to finish a project and have these two niggling problems: I'm using a script which uploads a picture, takes a note of where the picture has been put then outputs the path to that picture as a string. The string is appended to append to a .txt file which holds an array of similar paths. The array in the txt file is very simple: allpics=members/1/images/13.jpg,members/1/images/14.jpg,members/1/images/15.jpg, My questions are, once the script has opened the file 1) how can I append (edit) the array at a certain point i.e. not at the end but after the eighth character (allpics=)? and 2) how can I then count the commas in the whole array and write that number at the end as a variable "totalimges=123" ? Best wishes Monty Link to comment https://forums.phpfreaks.com/topic/177418-a-little-help-with-append-and-count-please/ Share on other sites More sharing options...
JonnoTheDev Posted October 12, 2009 Share Posted October 12, 2009 The array in the txt file is very simple: allpics=members/1/images/13.jpg,members/1/images/14.jpg,members/1/images/15.jpg, This is not an array it is a string. You should get rid of the allpics=members from this file. I do not understand why it is used in the first path? Create an array from the comma separator. You can then view the array, convert it back to a string. I have placed the file in a variable. Use file_get_contents() to read the file. <?php $textfile = "allpics=members/1/images/13.jpg,members/1/images/14.jpg,members/1/images/15.jpg"; $textfile = str_replace("allpics=","",$textfile); $filepaths = explode(",",$textfile); print "There are ".count($filepaths)." files"; print "<pre>"; print_r($filepaths); print "</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/177418-a-little-help-with-append-and-count-please/#findComment-935478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.