Jump to content

A little help with Append and Count please ?


MiniMonty

Recommended Posts

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

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>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.