Created
June 19, 2014 10:40
-
-
Save yitsushi/7f673d16c4e4e29b5de9 to your computer and use it in GitHub Desktop.
Egy alternatív megoldás ehhez a cikkhez: http://dev.folyam.info/2014/06/15/bevezeto-levagasa-regularis-kifejezessel/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wsplitAlt($value, $limit) | |
{ | |
$limited = substr($value, 0, $limit); | |
$nextSpaceValue = substr($value, 0, strpos($value, ' ', strrpos($limited, ' ') + 1)); | |
if ($limited === $nextSpaceValue) { | |
return $limited; | |
} | |
return substr($limited, 0, strrpos($limited, ' ')); | |
} |
mb_substr és mb_strrpos jobb lenne, ha magyar oldal is használja, mert substr az ékezetes betűket rosszul számolja (bár valószínűleg a dolog már nem túl aktuális 😄 )
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ha nincs space, akkor empty string-el ter vissza:
wsplitAlt('asdf', 200); => string '' (length=0)