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! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 11, 2014 Share Posted March 11, 2014 (edited) 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>'; Edited March 11, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.