At 4:16 PM -0700 4/1/01, Marcus Ouimet wrote:
>       How can i determine the number of characters in a string? I 
>am using substr
>to cut off the last 4 characters of a string. Which is working great. But I
>want to replace the 3 charcters with "..." only if there are over 20
>charcters . I tried substr_replace but it appears on everything no matter
>how many characters. I am trying to do this is simple terms:


Use strlen(). For example:

        $String = 'hi my name is';
        if (strlen($String) > 20) {
                $String = substr($String, 0, 17).'...';
        }

In PHP4, you can use the substr_replace() function to replace the 
third line in the example above:

        $String = 'hi my name is';
        if (strlen($String) > 20) {
                $String = substr_replace($String, '...', 17);
        }

For more information, see

        http://www.php.net/manual/en/function.strlen.php

        http://www.php.net/manual/en/function.substr.php

        http://www.php.net/manual/en/function.substr-replace.php

-steve


>if the string was:
>
>hi my name is
>
>it is returned shortened to:
>
>hi ...
>
>       Any help appreciated.
>

-- 
+----------- 12 April 2001: Forty years of manned spaceflight -----------+
| Steve Edberg                           University of California, Davis |
| [EMAIL PROTECTED]                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------- www.yurisnight.net --------------------------+

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to