php: transforming a array to string
- thingie-348
-
thingie-348
- Member since: Nov. 27, 2005
- Offline.
-
- Forum Stats
- Member
- Level 07
- Blank Slate
how do you transform an array into a string on php? I want to do a "leave a comment" page, where all the comments get on a file called "mess.txt" separated by a "^", so I put
$p = fopen("mess.txt", "r") ;
$a = new Array() ;
$c = 0 ;
$r = 0 ;
while (($c = fgetc($p)) != '^')
{
$a[$r] = $c ;
$r++ ;
}
and how do I echo $a to the screen?
- thingie-348
-
thingie-348
- Member since: Nov. 27, 2005
- Offline.
-
- Forum Stats
- Member
- Level 07
- Blank Slate
- elbekko
-
elbekko
- Member since: Jul. 23, 2004
- Offline.
-
- Forum Stats
- Member
- Level 16
- Blank Slate
implode() to glue an array together
print_r() to show an array
"My software never has bugs. It just develops random features. " - Unknown
[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]
- JeremysFilms
-
JeremysFilms
- Member since: Feb. 18, 2005
- Offline.
-
- Forum Stats
- Member
- Level 18
- Blank Slate
First off, you need to use implode() to take a string and turn it into an array by a separator. One thing to keep in mind, however, is that you should not use ^ as a separator. You should use something that won't be as common to be typed. Something maybe like <--SEPARATOR--> and then restrict it from being entered as a comment or make <'s and >'s become their html entities of < and > (which you should do anyway for security reasons) and that way it would be impossible for <--SEPARATOR--> to be entered since <'s would become < and therefore make it not be picked up by PHP.
PS. Consider moving into databases after you've progressed with txt file manipulation.

