Shortening a fetched array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ViperBlade
    New Member
    • Feb 2007
    • 2

    Shortening a fetched array

    Hi, i'm unsure of the versions of MySQL and PHP I'm using (although my webhost 'guarantees' the latest), but I don't think the answer would vary that much between versions.
    Now to the point:
    I'm trying to echo text fetched from a database into a 128px width column, which doens't always fit. I'd like to know how to shorten the results of an array using '...'s like: 'Amer...' or 'Urag...' instead of 'America' or 'Uraguay'.

    Thank you,
    ViperBlade
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by ViperBlade
    Hi, i'm unsure of the versions of MySQL and PHP I'm using (although my webhost 'guarantees' the latest), but I don't think the answer would vary that much between versions.
    Now to the point:
    I'm trying to echo text fetched from a database into a 128px width column, which doens't always fit. I'd like to know how to shorten the results of an array using '...'s like: 'Amer...' or 'Urag...' instead of 'America' or 'Uraguay'.

    Thank you,
    ViperBlade
    Welcome to theScripts ViperBlade!
    This task will be quite difficult unless you are using a monospaced font.

    Comment

    • ViperBlade
      New Member
      • Feb 2007
      • 2

      #3
      Originally posted by Motoma
      Welcome to theScripts ViperBlade!
      This task will be quite difficult unless you are using a monospaced font.
      True, but i'll be using Lucidia Sans Console. Do you have any ideas? I know it's
      possible because phpMyAdmin shortens certain fields with '...'s.

      Thanks for the welcome,
      ViperBlade

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by ViperBlade
        True, but i'll be using Lucidia Sans Console. Do you have any ideas? I know it's
        possible because phpMyAdmin shortens certain fields with '...'s.

        Thanks for the welcome,
        ViperBlade
        In order to fit it correctly inside a certain pixel width, you would have to calculate the width of each character, and the truncate the string, and append "..."

        Comment

        Working...