Help with display length

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mattmcb
Forum Commoner
Posts: 27
Joined: Sun Jan 25, 2004 3:34 pm

Help with display length

Post by mattmcb »

Can someone help me out with setting the display length for this code:

Code: Select all

<?php
	while ($row_send = mysql_fetch_array($result_send))
	{    
		echo ('<option value="'.$row_send['user_id'].'">'.$row_send['username'].' | '.$row_send['storename'].' | '.$row_send['companyname'].'</option>');
		}

?>
Basically, three values are being pulled from the DB and used to create a dropdown liast for the user to select. I would only like to display the first 25 characters of each value; how do I do that? Even if the value is less then 25 characters I still want 25 characters to display so there would be blank spaces after the value.

Any help would be appreciated!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

not absolutely sure here but:

Code: Select all

<?php 

   function first25($string) { return str_replace(' ','&'.'nbsp;',sprintf("%25s",$string)); }
   while ($row_send = mysql_fetch_array($result_send)) 
   {    
      echo ('<option value="'.$row_send['user_id'].'">'.first25($row_send['username']).' | '.first25($row_send['storename']).' | '.first25($row_send['companyname']).'</option>'); 
      } 

?>
should be left aligned now.
Post Reply