Forum Moderators: coopster

Message Too Old, No Replies

Change Returns to Comma Separated Strings?

         

internetheaven

10:31 am on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anyone know how to turn a list e.g.

widget 1
widget 2
widget 3
etc.

into comma separated list i.e.

widget 1, widget 2, widget 3 etc.

I found stuff like m_iscommadelimited and m_ getcommadelimited but there is not a lot of explanation on how to write these.

Thanks
Mike

ayushchd

10:34 am on Nov 17, 2007 (gmt 0)

10+ Year Member



Is this list retuened by a mysql query?

internetheaven

10:44 am on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, it is called from a txt file.

Thanks
Mike

ayushchd

10:47 am on Nov 17, 2007 (gmt 0)

10+ Year Member



Can u please post that part of the code, which generates this list?

internetheaven

10:57 am on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't quite understand?

The file will be called but the list is vertical and I want comma separated to appear on the page so the code is just currently file_get_contents to pull the file. I'm looking for rest ...

ayushchd

11:06 am on Nov 17, 2007 (gmt 0)

10+ Year Member



I have written this... I hope this helps :
$file = fopen("a.txt", "r");
while(!feof($file))
{
$file_contents .= fread($file, 2048);
}
$content = explode("\n", $file_contents);
$req_output = implode(", ", $content);
echo $req_output;

ayushchd

2:14 pm on Nov 17, 2007 (gmt 0)

10+ Year Member



Well, I tried again...this works better..

$content = explode("\r\n", $file_contents);

Actually, it depends on the way the list is kept in the txt file...

Does it work for you?

internetheaven

2:55 pm on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first one seems to have worked fine, thanks!

ayushchd

3:08 pm on Nov 17, 2007 (gmt 0)

10+ Year Member



Welcome, Mike!

Ayush