Jump to content


Photo

Cant implode my data?


  • Please log in to reply
2 replies to this topic

#1 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 29 May 2006 - 06:02 AM

I am useing a foreach loop to collect information for a file

the info is stored as

blah blah blah |~|blah blah blah |~|blah blah blah |~|blah blah blah |~|blah blah blah

within my loop i have the following

$store .= $filedata[$col]."|~|";

this collects differt info depending on the line. but my problem is when I tryed to implode the $tore it would not work?

this is the code i used to implode
$wanted_info = implode("|~|", $store);

and this is the error i get
Warning: implode(): Bad arguments

I know the info is in $store as i can echo this out and its all fine?
The best way to learn
is to ask you lot........

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 29 May 2006 - 06:18 AM

The implode() function takes an array and returns a string with the seperater given between each element.
The explode() function takes a string with elements seperated by a string and returns an array.

You're using the wrong function. You want to use the explode() function. But if you're just going to explode the string you just created and put the results into an array, why don't you do that in the first place:
<?php $wanted_info[] = $filedata[$col]; ?>
If you still want the deliminated string you can create it from the $wanted_info array:
<?php $store = implode('|~|',$wanted_info); ?>

Ken

#3 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 29 May 2006 - 06:25 AM

I never new you could do this
<?php $wanted_info[] = $filedata[$col]; ?>

anyway it works, thanks :)
The best way to learn
is to ask you lot........




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users