neugi Posted June 28, 2006 Share Posted June 28, 2006 Hi, i've got a string that i need to separete. the string is always in the same length of 97 charshere is my code that i use:[code]$daten = "290122105555910000 HZ LEGEND AIR 0001840000130200100232"$lange = strlen($daten); $ean = substr($daten, 0, 13); $text = substr($daten, 13, 60); $filial_vk = substr($daten, 60, 7); $duch_ek = substr($daten, 67, 7); $mwst = substr($daten, 74, 1); $hw_grp = substr($daten, 75, 2); $uwgr = substr($daten, 77, 4); $status = substr($daten, 81, 1); echo $ean . '-' . $text .' - '. $filial_vk .' - '. $duch_ek . ' - '. $mwst . ' - '. $hw_grp . ' - '. $uwgr . ' - '. $status ."<br>\n";[/code]but the output is only[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]2901221055559-10000 HZ LEGEND AIR - - 0 - 0 - 01 - 8400 - 0[/quote]what is wrong with this code?best Link to comment https://forums.phpfreaks.com/topic/13114-substr-problem/ Share on other sites More sharing options...
Buyocat Posted June 28, 2006 Share Posted June 28, 2006 If you're sure of the length then this doesn't really seem like a tricky problem; to start I would remove all that white space from the string, I think that would just get in your way... try using trim(). Anyway, it also looks like some of your substr's are going from the middle/end of the string to the front, that is they are wrapping around. At any rate, it looks like $duch_ek is being set to '' which I believe is due to that white space. If you want more help then please specify what you expected to get as output and any errors thrown. Link to comment https://forums.phpfreaks.com/topic/13114-substr-problem/#findComment-50428 Share on other sites More sharing options...
neugi Posted June 28, 2006 Author Share Posted June 28, 2006 hi,the string should be splittet into fields with the length of:13/60/7/7/1/2/4/1 charsthere where the 60 chars are the length of the text and the white spaces are not fix, so there can be only 3 chars and 57 white spaces. the trick with the trim function is working. thx Link to comment https://forums.phpfreaks.com/topic/13114-substr-problem/#findComment-50435 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.