Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Creating strings of X length based on array
- Array
- (
- [0] => Array
- (
- [name] => shirt
- [price] => 1.25
- )
- [1] => Array
- (
- [name] => car
- [price] => 25.10
- )
- ...
- )
- $str = "";
- foreach($arr as $v) {
- $str .= "<name>".$v['name']."</name>";
- $str .= "<price>".$v['price']."</price>";
- }
- str1 = '<name>shirt</name><price>1.25</price><name>car</name><price>25.10</price>...' // until 500 bytes or less.
- str2 = '<name>shirt</name><price>1.25</price><name>car</name><price>25.10</price>...' // until 500 bytes or less.
- str = '<name>flower</name><pri';
- $xml = array();
- $str = '';
- foreach($arr as $v)
- {
- $temp = "<name>".$v['name']."</name>";
- $temp .= "<price>".$v['price']."</price>";
- if(mb_strlen($str . $temp) > 500)
- {
- $xml[] = $str;
- $str = '';
- }
- $str = $temp;
- }
- $xml[] = $str;
- print_r($xml);
Advertisement
Add Comment
Please, Sign In to add comment