Jump to content


Photo

Substr Problem


  • Please log in to reply
2 replies to this topic

#1 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 28 June 2006 - 02:47 PM

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:
$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";
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

#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 28 June 2006 - 02:54 PM

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.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 28 June 2006 - 03:09 PM

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users