mabog Posted February 27, 2010 Share Posted February 27, 2010 I'm having trouble adding more tabs at the end of the line but BEFORE line feed. I can find position of the line feed, but is there a function which can add text in string with position defined? The string is like this: "blaa\tblaa\t12345\tblaa\t*more tabs here*\n" Quote Link to comment Share on other sites More sharing options...
jskywalker Posted February 27, 2010 Share Posted February 27, 2010 It (the linefeed) seems to be at the end of your string.... But i think that simplifies your problem too much? $text="blaa\tblaa\t12345\tblaa\t*more tabs here*\n" print substr($text,0,strlen($text)-1); print "\t\t\t\t\t\t\t"; Quote Link to comment Share on other sites More sharing options...
harristweed Posted February 27, 2010 Share Posted February 27, 2010 jskywalker got there first.... $string="blaa\tblaa\t12345\tblaa\t*more tabs here*\n"; $length=strlen($string); $string_no_n=substr($string,0,($length-2)); $more_tabs="\t\t\t\n"; $new_string=$string_no_n.$more_tabs; Quote Link to comment Share on other sites More sharing options...
mabog Posted February 27, 2010 Author Share Posted February 27, 2010 Thanks for the answers! Actually problem was not \n, it was \r ... Solved with this: $exploded=explode("\r\n",$str); $str=$exploded[0]."\t\r"; But I'm curious why I can't put \n back? Like this: $exploded=explode("\r\n",$str); $str=$exploded[0]."\t\r\n"; Doesn't work... but does it really need it? Quote Link to comment Share on other sites More sharing options...
jskywalker Posted February 27, 2010 Share Posted February 27, 2010 Doesn't work... but does it really need it? it totally depends on what you want to do with this string.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.