Page 1 of 1
combo box returning a space at the end?
Posted: Thu Jun 19, 2003 1:07 pm
by slipstream
I have a combo box where the user selects files to delete. then I add a ".txt" to it so the user can delete a txt file of their choice.
Anyway this is what it returns:
myfile .txt
when there shouldn't be a space after the name and the .txt. Any ideas how to remove it?
Posted: Thu Jun 19, 2003 1:34 pm
by Galahad
Can you show us how the box is being created? If all else fails, you can do a trim or rtrim on the string before you append ".txt" to it.
Posted: Thu Jun 19, 2003 1:47 pm
by slipstream
the box is being created like this:
echo '<option value="-1">Please Select...</option>';
foreach($file as $line)
{
$info = explode('|', $line);
echo '<option value="'.$info[0].'">'.$info[0].'</option>';
}
echo '</select><BR><BR>';
Posted: Thu Jun 19, 2003 1:55 pm
by Galahad
I suspect your $line is formatted something like "text you want | stuff you don't want". If that's right, when you call
it will leave the space in. Again, assuming my guess about the format is right, you could do
Code: Select all
<?php
explode(" | ", $line); // Note the spaces around the '|' character
?>
to get rid of the spaces, too.
If it isn't always " | ", you could explode on just "|" like you are and do something like:
Code: Select all
<?php
echo '<option value="'.trim($info[0]).'">'.trim($info[0]).'</option>';
?>
when you make the box.