Be a Supporter!

php: transforming a array to string

  • 313 Views
  • 3 Replies
New Topic Respond to this Topic
thingie-348
thingie-348
  • Member since: Nov. 27, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
php: transforming a array to string 2006-07-10 15:19:40 Reply

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
Response to php: transforming a array to string 2006-07-10 15:27:41 Reply

cmon reply

elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to php: transforming a array to string 2006-07-10 16:20:10 Reply

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 ]

BBS Signature
JeremysFilms
JeremysFilms
  • Member since: Feb. 18, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to php: transforming a array to string 2006-07-10 16:42:55 Reply

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 &lt; and &gt; (which you should do anyway for security reasons) and that way it would be impossible for <--SEPARATOR--> to be entered since <'s would become &lt; and therefore make it not be picked up by PHP.

PS. Consider moving into databases after you've progressed with txt file manipulation.