Results 1 to 12 of 12

Thread: Text Length

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Text Length

    Is there a way to tell how many pixels certain text will take up?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    how many pixels? well by depault it is 10px, but I take it that is not what you are after. if you want the same thing like an image on how many pixels it is then that is a good question.

    why would you want to know this, for curiousity reasons?

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    I'm guessing he wants to know if there is a PHP equivelent function to VB .TextWidth's. I can see it would be usefull to know if, oh let's say, add text, just to use a nonspecific example, is going to take up more than 500pixels on someone's screen.
    Then you could mak necessary adjustments to avoid a flood of backlash when the users of the site are suddenly subjected to the outrageous 72point sized text.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    not that I am aware of. the only thing that would come close is strlen(), but that will noly tell you how many characters it has.

    but how can it get to 75points if the webmaster doesn't set it that way? the pixel size is controlled by the browser unless you specificly state it in the css.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    75points <> 75pixels.

    If I set something to Size=5, I have no way of knowing if that's 100px, or 50px. Plus, what may look OK in one rez, looks completely whacko in another.

    But then, I was just using it as an example.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    well if you new your fonts then you should know what size is 5. it is expained at www.w3.org pretty well. but again the browser can only go so big.

    I see where you are coming from and I do know that one size on one pc is different than another.

    but again it is the webmaster not the user that sets the font size. os php would have no idea how big it is.

  7. #7

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'll try to provide a specific example later...but I need a table cell's width to be a little more of the width of it's text.

    I know that setting it to nothing would do that automatically...I'll try to provide an example later, but I'm busy now.

    Thanks for your help so far.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    actually that explains a lot and I hav eto tell you that php has little control, if none, over DOM so you would be better off with javascript.

  9. #9

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I really don't care what language does it. If you know how to do it in JS, then by all means, clue me in.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Here is what I'm trying to do:

    Code:
    <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
            <td width="10">
                <table border="0" cellspacing="0" cellpadding="0" style="width: 100%;">
                    <tr>
                        <td height="5" bgcolor="#dba842"><img src="space.gif" height="5"></td>
                    </tr>
                </table>
            </td>
            <td align="center" valign="middle" style="font-size: 9pt; width: 180px;"><b>' . $text . '</b></td>
            <td> 
                <table border="0" cellspacing="0" cellpadding="0" style="width: 100%;">
                    <tr> 
                        <td height="5" bgcolor="#dba842"><img src="space.gif" height="5"></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    Is there any way I can do this? I never know what $text is going to be.

    http://www.vbshelf.com/layout is an example of it. It's the orange line around "Compiler Companion v1.0"

    Any ideas?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    you know you could use strlen() on the $text and just add something to it for the width.

    ex.

    PHP Code:
    $text_len strlen("some text");  //  9
    $width $text_len +20;

    <
    td align="center" valign="middle" style="font-size: 9pt; width: {$width}px;"
    somethnig like that would work.

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Oh, well, I get it now..... don't use width in the style.... try this instead....
    Code:
    PADDING-RIGHT: 5px; PADDING-LEFT: 5px
    This will put 5pixels on the left and right of the TD cell.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width