Reply
String Pad Help
Old 07-04-2004, 07:55 PM String Pad Help
Novice Talker

Posts: 9
Does anyone have any ideas on why this won't work? I'm pulling a variables from the DB and I want to display them in a list evenly spaced out. But the str_pad function does not seem to be working so I must be doing something wrong:

PHP Code:
    // Display member list for private message selection
    
while ($row_add mysql_fetch_array($result_add))
    {   
        echo (
'<option value="'.$row_add['user_id'].'">'.str_pad($row_add['username'],35).' | '.str_pad($row_add['storename'], 25).' | '.str_pad($row_add['companyname'], 25).'</option>');
    } 
mattmcb is offline
Reply With Quote
View Public Profile Visit mattmcb's homepage!
 
When You Register, These Ads Go Away!
     
Old 07-04-2004, 08:26 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
matt,

The problem is not with PHP, but with your browser and HTML in general. The spaces are there, but remember that browsers ignore extra spaces and line feeds and are doing so here.

Try this code:

PHP Code:
echo ('<option value="' .$row_add['user_id'].'">' 
       
padWithHTMLSpaces($row_add['username'],35). ' | ' 
       
padWithHTMLSpaces($row_add['storename'], 25). ' | ' 
       
padWithHTMLSpaces($row_add['companyname'], 25
       . 
'</option>'); 


// You'll need this little function
function padWithHTMLSpaces$szin$targetLength )
{
    
$szout str_pad$szin$targetLength" "STRING_PAD_RIGHT );
    return 
str_replace" ""&nbsp;"$szout );

Hope this helps.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Reply     « Reply to String Pad Help
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12011 seconds with 13 queries