Jump to content

[SOLVED] strlen help needed


acctman

Recommended Posts

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

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
*/

?>

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,

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'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.