I want to call a file, and print its contents, in the file I want to have some text seperated by a delimiter (%% for example: AAAA%% BBBB%% CCCC%% DDDDDDD%% and so on...) whatever I try does not work, anyone can help me out please? here is what I have: $data = file_get_contents("file1.csv"); $data = explode('%%', $data); $printme .= "\n" . $data; echo $printme; the above code does nothing, no error either. thanks
Thanks for reply, you mean to have it this way: $data = file_get_contents("file1.csv"); $data = explode('%%', $data); print_r($data); it did not work,
I run this script and the only thing is printed is "array" without quotes, <?php $data1 = file_get_contents("file1.csv"); $data1 = explode('%%', $data1); $printme .= "\n" . $data1; echo $printme; ?>
Like Alga mentioned try the print_r function to print the array data. file_get_contents() returns the file as a string, if we simulate this with the following php code <?php $fileSimulation = '%% for example: AAAA%% BBBB%% CCCC%% DDDDDDD%%'; $data = explode('%%', $fileSimulation); print_r($data); ?> PHP: It will print this Array ( [0] => [1] => for example: AAAA [2] => BBBB [3] => CCCC [4] => DDDDDDD [5] => ) PHP: If it doesn't it might be as fscripting mentioned that file might have failed opening. If the file_get_contents() failes it will return false.
thank you for your responds, of course I understand that the code I have is for string, the code that you offerd worked very well and it showed what you posted, but it does not work with what I want to do, I don't want to have my data as some value in a variable, I simply want to get my data from a file, that is why I use file_get_contents() function, and I dont want to print all of the data at once, every piece of data in between %% should be printed seperatly, but this is not the issue here, for now if it prints the data, I believe i have solved my problem. but I don't know wha I do wrongly that it does not work, fscripting I have alreay tried with | sign, it does not make any different, thanks
Do u wanna do something like this eg - AAAA%% BBBB%% CCCC%% DDDDDDD%% u wanna print "ccccc" and rest u dont wanna print rite if u wanna do like that try to print " print_r($data[2]);" as it is the third value
thanks for reply fscripting ; yes I know that, well, I have a plug in for wp blog, it does count my post (whenever there is one), and after a certain number of words it suppose to add a some small text from a file, the first count it will add AAAA the second count it will add BBB and so on... it is sequential and when it reaches to the end it will start again. it is very easy to handle a file of data seperted by a delimiter, you can take some text out or add one easly and reupload the file, but with variable in a php file it is not easy to do, thanks