Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 389901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:54:43+00:00 2026-05-12T15:54:43+00:00

I have ran into a bit of problem. Originally, I have the following input

  • 0

I have ran into a bit of problem. Originally, I have the following input of the format:

12345     apple
12     orange

I saved the first column as $num and second column as $fruit. I want the output to look like this (see below). I would like for the output to align as if the $num are of all the same length. In reality, the $num will consists of variable-length numbers.

12345     apple
12        orange

As suggested, I use the following code:

$line = sprintf "%--10s %-20s", $num, $fruit;

This solution works great in command-line display, but this formatting is not retained when I try to display this via HTML. For example..

print "<html><head></head><body>
        $line
        </body></html>";

This produces the same output as the original before formatting. Do you guys have a suggestion as to how I can retain the sprintf formatting in html web-based display? I try to pad the $num with whitespaces, but the following code doesn’t seem to work for me.

$num .= (" " x (10 - length($num)));

Anyways, I would appreciate any suggestions. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:54:44+00:00Added an answer on May 12, 2026 at 3:54 pm

    HTML ignores extra whitespace. And the fact that it’s probably displaying with a proportional font means it wouldn’t line up even if the extra spaces were there.

    The easy option is to just surround the text with <pre> tags, which will display by default with a monospace font and whitespace preserved. Alternatively, you can have your code generate an HTML table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently developing a PHP framework and have ran into my first problem. I need
I recently started programming my first Cocoa app. I have ran into a problem
I have ran into a bit of a problem with my understanding of the
I have started to play around with boost python a bit and ran into
I have ran into a bit of trouble getting my pong game to work,
i ran into a bit of a problem and i don't see how to
I have a mapView with custom annotations and just ran into a problem on
I've ran into a bit of a stupid problem today: In my project I
I have ran into an interesting issue while trying to create a more usable
I'm currently getting to grips with mod_rewrite and have ran into a stumbling block

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.