Hello, I am interested in the following question :
How to break the string coming from the database, for the subsequent entry of parts of this row into the table, where part 1 is column 1, etc? For example, there is a string Материал: сталь; , further Страна производитель: Россия; (this is all one line) so I need the Материал и Страна производитель put in the cells on the left, and сталь и Россия in the corresponding right cells, how can this be done? Hopefully I could explain.
- Strange type of data storage. Well dy okay - dirkgntly
- @dDevil I know that it is rational to create reference books, but as a study I decided what to do in this way - Denis
|
2 answers
The explode('разделитель', $srt) function explode('разделитель', $srt) splits a string into an array.
Beat 2 times. First with the delimiter ';' , then array elements by ':'
- How can I then write these parts into the table - Denis
- $ a = explode (';', $ srt); as array elements just <td> <? php echo $ a [0];?> </ td> - Boris Runs
- already figured out, thank you) - Denis
- oneit’s wrong, but I wouldn’t advise storing data like that, a very crutch-like conclusion is obtained ... - Boris Runs
- I understand everything, it is only within the framework of training) - Denis
|
If briefly, then so:
$dbRows = array_map( function($row){ return array_map('trim', explode(':', $row)); }, explode(';', $sourceString) ); explode - breaks a string into an array
array_map - applies an element to each element
|