Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created June 19, 2014 10:40
Show Gist options
  • Save yitsushi/7f673d16c4e4e29b5de9 to your computer and use it in GitHub Desktop.
Save yitsushi/7f673d16c4e4e29b5de9 to your computer and use it in GitHub Desktop.
<?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, ' '));
}
@vegvari
Copy link

vegvari commented Jun 20, 2014

Ha nincs space, akkor empty string-el ter vissza:

wsplitAlt('asdf', 200); => string '' (length=0)

@tujlaky
Copy link

tujlaky commented Dec 19, 2014

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