kraybrett Posted March 11, 2014 Share Posted March 11, 2014 I am new to coding and working on a website, I have data coming from my data base in this format to my product description area: Length=8 in|Width=0.180 in|Thickness=|Size Group=|Bundle Diam=1.9000 in [Max]|Material=Nylon|Color=Weather Resistant I need to somehow convert the data to this format in an HTML table in the same area: Length 8 in Width 0.180 in Thickness Size Group Bundle Diam 1.9000 in [Max] |Material=Nylon Color=Weather Resistant I know it seems friggin easy, but I am stumped! Any help will be appreciated! Link to comment https://forums.phpfreaks.com/topic/286890-converting-data-into-html-table/ Share on other sites More sharing options...
Ch0cu3r Posted March 11, 2014 Share Posted March 11, 2014 explode on the | (pipe). Use foreach to loop over the returned array. In the loop start a new table row (<tr>) and a new table cell (<td>). For the current item use str_replace to replace the = with </td><td> after close the table cell (</td>) and the table row (</tr>). Code: $data = 'Length=8 in|Width=0.180 in|Thickness=|Size Group=|Bundle Diam=1.9000 in [Max]|Material=Nylon|Color=Weather Resistant'; echo '<table>'; foreach(explode('|', $data) as $item) { echo '<tr><th>'.str_replace('=', '</th><td>', $item) . '</td></tr>'; } echo '</table>'; Link to comment https://forums.phpfreaks.com/topic/286890-converting-data-into-html-table/#findComment-1472229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.