|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-01-01 02:05 UTC] jc at mega-bucks dot co dot jp
Could you add a multibyte version of the str_pad function to the mbstring library functions? Thanks, Jc PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 14:00:01 2025 UTC |
Great! Please update the bug report when you have implemented a solution so that I can download it and try it out! (as I said, my solution isn't working in all cases). As for your question, as I see it, the only way that this could happen where if the user supplied a double-width character for the padding string *and* we assume that the pad_length is a count in single-width. But I don't think the problem your present is any different that the problem that str_pad has when passed arguments like this: str_pad("1", 2, "--"); In this example adding the pad string would produce a string longer than is requested. I just tested this code out and PHP gives "1-", which in my opinion is a bug ... I was going to say that the mb version should adopt the same behaviour but since the str_pad behaviour seems to be wrong (in my poor opinion) I am not sure what the correct behaviour should be. I guess one way would be to add a parameter, pad_with_half_width_space, that would let the user decide wether to pad with a half-width space or not if the input string lentgh cannot be divided by the length of the string to pad with. Or, you could say that the behaviour of the function is to *always* pad with half-width spaces by default. But then we have the problem of what to do if the user wants to pad a string of length 2, to be length 5 and the padding character is 2 wide ... we can pad up to length 4, but what to do with the remaining half-width, (pad with a half space? Do nothing?) I can't think of any answer that is "correct", so suggest putting your foot down, defining the what the behaviour will be in those cases and if you feel generous adding parameter to the function to change the default behaviour. Thanks!