acctman Posted April 27, 2009 Share Posted April 27, 2009 i'm using the strlen code below everything works fine, except its not taking into account spaces. whatever text $en['m_user'] holds should be counted. if a name is JohnDoe1234 and John Doe1234, the second version with the space should be strlen as well after the 8 character "e". <?php $en['len_user'] = strlen($en['m_user']) > 11? substr($en['m_user'],0,."...": $en['m_user']; ?> Link to comment https://forums.phpfreaks.com/topic/155873-solved-strlen-help-needed/ Share on other sites More sharing options...
Cosizzle Posted April 27, 2009 Share Posted April 27, 2009 Im sorry I don't quite understand the question... I made a quick script to show output <?php $str = 'JohnDoe1234'; echo strlen($str); // 11 echo '<br>'; echo substr($str, 0, ; // JohnDoe1 echo '<hr>'; $str = 'John Doe1234'; echo strlen($str); // 12 echo '<br>'; echo substr($str, 0, ; // John Doe /** 11 JohnDoe1 12 John Doe */ ?> Link to comment https://forums.phpfreaks.com/topic/155873-solved-strlen-help-needed/#findComment-820434 Share on other sites More sharing options...
Demonic Posted April 27, 2009 Share Posted April 27, 2009 Use the explode function, and explode the spaces. test test exploding space would split that into 2 arrays, subtract 1 from the total: function real_strlen( $string ) { $count = count(@explode($string," ")); $count = strlen($string) - ( $count - 1 ); return $string; } Make that into a function, Link to comment https://forums.phpfreaks.com/topic/155873-solved-strlen-help-needed/#findComment-820439 Share on other sites More sharing options...
acctman Posted April 27, 2009 Author Share Posted April 27, 2009 Use the explode function, and explode the spaces. test test exploding space would split that into 2 arrays, subtract 1 from the total: function real_strlen( $string ) { $count = count(@explode($string," ")); $count = strlen($string) - ( $count - 1 ); return $string; } Make that into a function, the code would be something like this? $count = count(@explode($en['m_user']," ")); $count = strlen($en['m_user']) - ( $count - 1 ); $en['len_user'] = strlen($en['m_user']) > 11? substr($en['m_user'],0,."...": $en['m_user']; Link to comment https://forums.phpfreaks.com/topic/155873-solved-strlen-help-needed/#findComment-820503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.