Jump to content

Archived

This topic is now archived and is closed to further replies.

neugi

Substr Problem

Recommended Posts

Hi,

i've got a string that i need to separete. the string is always in the same length of 97 chars

here 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
hi,

the string should be splittet into fields with the length of:
13/60/7/7/1/2/4/1 chars

there 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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.