Guest User

Untitled

a guest
Apr 25th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. Creating strings of X length based on array
  2. Array
  3. (
  4. [0] => Array
  5. (
  6. [name] => shirt
  7. [price] => 1.25
  8. )
  9.  
  10. [1] => Array
  11. (
  12. [name] => car
  13. [price] => 25.10
  14. )
  15. ...
  16. )
  17.  
  18. $str = "";
  19.  
  20. foreach($arr as $v) {
  21. $str .= "<name>".$v['name']."</name>";
  22. $str .= "<price>".$v['price']."</price>";
  23. }
  24.  
  25. str1 = '<name>shirt</name><price>1.25</price><name>car</name><price>25.10</price>...' // until 500 bytes or less.
  26. str2 = '<name>shirt</name><price>1.25</price><name>car</name><price>25.10</price>...' // until 500 bytes or less.
  27.  
  28. str = '<name>flower</name><pri';
  29.  
  30. $xml = array();
  31. $str = '';
  32. foreach($arr as $v)
  33. {
  34. $temp = "<name>".$v['name']."</name>";
  35. $temp .= "<price>".$v['price']."</price>";
  36.  
  37. if(mb_strlen($str . $temp) > 500)
  38. {
  39. $xml[] = $str;
  40. $str = '';
  41. }
  42. $str = $temp;
  43. }
  44. $xml[] = $str;
  45.  
  46. print_r($xml);
Advertisement
Add Comment
Please, Sign In to add comment