How to create table rows data from a tokenized value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
santdas
Forum Newbie
Posts: 2
Joined: Thu May 13, 2004 2:27 am

How to create table rows data from a tokenized value

Post by santdas »

Hi All,

I have one value as:

$searchVal = "e:\\shared\\Alihaider-purani jeans.mp3||AliHaider - Purani Jeans@@e:\\shared\\KantaLaga.mp3||DJ Doll - Kanta Laga@@" ;

How can I create a table from this value in following way:
(Each table row data is separated by "@@" and the displayed TD data is the second token in every row value, separated by"||")

<TABLE>

<TR>
<TD vAlign=center align=left bgColor=#2e2e2e height=30>
<input type='hidden' name='row1' value='e:\\shared\\Alihaider-purani jeans.mp3||AliHaider - Purani Jeans'>
AliHaider - Purani Jeans
</TD>
</TR>


<TR>
<TD vAlign=center align=left bgColor=#2e2e2e height=30>
<input type='hidden' name='row1' value='e:\\shared\\KantaLaga.mp3||DJ Doll - Kanta Laga'>
DJ Doll - Kanta Laga
</TD>
</TR>

</TABLE>


Please help me. Its very urgent.

Thanks in advance.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<table>
<?php
$searchvar = "e:\\shared\\Alihaider-purani jeans.mp3||AliHaider - Purani Jeans@@e:\\shared\\KantaLaga.mp3||DJ Doll - Kanta Laga@@";
$songs = explode("@@",$searchvar);

foreach($songs as $k => $song)
{
  if(empty($song))
    continue;
  list($file,$name) = explode("||",$song);
  echo<<<EOD
<tr>
<td vAlign=center align=left bgColor=#2e2e2e height=30><input type='hidden' name='row$k' value='$song'>$name</td>
</tr>
EOD;
}
?>
</table>
[edit:oops. mistyped empty()]
Last edited by feyd on Thu May 13, 2004 4:55 am, edited 1 time in total.
santdas
Forum Newbie
Posts: 2
Joined: Thu May 13, 2004 2:27 am

Post by santdas »

oh, it worked. Thanks a lot feyd!!
Post Reply