1

I successfully managed to run my first php script in a web page!! I'm using a Raspberry Pi and with this script, a result is shown in a php page. It shows METAR data from the local airport.

Basically meteo data. I managed to center the output on the page using the string

> echo "<center>";

It looks nice, but would be nicer if it can be displayed with its original left justification in a centered html table.

Is this possible?

!DOCTYPE html>
<div align="center">
<hr />
<h1>METAR report</h1>
<?php
 $output = shell_exec('sh /var/www/html/weather.sh');
 echo "<pre>$output</pre>";
 ?>



3
  • 1
    What "table" are you referring to? We have no clue what the variable $output contains. Please read How to create a Minimal, Reproducible Example and edit your question accordingly. Commented Sep 18, 2019 at 12:50
  • Hi! well the output of the shell is a simple weather report on 13 lines displayed on a php web page hosted on my server. The same text as i get on the linux terminal. I centered the text on the page but i would like to maintain its left justification and insert the weather report in a table, a sort of frame. Commented Sep 18, 2019 at 13:23
  • Just echo the data in a div that has align: left. Example: <div style="align: left"><?php ... ?></div>. Commented Sep 18, 2019 at 13:28

2 Answers 2

3

Try the following:

<!DOCTYPE html>
<html>
    <head>
        <title>Project</title>
    </head>
    <body>
        <div class="container">
            <?php
                $output = shell_exec('sh /var/www/html/weather.sh');
                echo "<pre>$output</pre>";
            ?>
        </div>
        <style>
        .container {
            width: 90%;
            margin: 0 auto;
        }
        </style>
    </body>
</html>
Sign up to request clarification or add additional context in comments.

3 Comments

Hi! Well the text has a bit of space from the left margin and it is justified on the left. Not bad. Is it possible to add everything inside an html table, like if it was in a frame...
@Antonio Using tables without actually requiring tables is bad practise these days. You can simply give the .container a background colour to make it look better. You can also decrease the width to make it more centered.
Ok, thanks for the tip. I won't use any frame. Looks surely cleaner.
0
<!DOCTYPE html>
<html>
    <head>
        <title>Project</title>
    </head>
    <body>

    <?php
 $output = shell_exec('sh /var/www/html/weather.sh');
 ?>
    <table align="center" width="400" border="1">
        <tr>
            <td><?php echo "<pre>$output</pre>"; ?></td>
        </tr>
    </table>
    <table align="center" width="400" border="0">
        <tr>
            <td><?php echo "<pre>$output</pre>"; ?></td>
        </tr>
    </table>
    <table align="center" width="800" border="1">
        <tr>
            <td><?php echo "<pre>$output</pre>"; ?></td>
        </tr>
    </table>
    </body>
</html>

Try all combinations and choose which one suits you best. viva l'Italia!

6 Comments

You should not teach people bad practises based on what they want, but rather teach them what the right thing to do is.
@AaronNoHuanKnows is this ok? <!DOCTYPE html> <html> <head> <title>Metar Report</title> </head> <body> <?php $output = shell_exec('sh /var/www/html/weather.sh'); ?> <table align="center" width="400" border="0"> <tr> <th><h1>Metar Report</h1></th> </tr> <tr> <td><?php echo "<pre>$output</pre>"; ?></td> </tr> </table> </body> </html>
@Antonio Not according to today's standards. If anything you should look into installing "Bootstrap" through a CDN and using their container class.
@AaronNoHuanKnows ok! Now i know how it works. I'll study the CSS you gave me and the html code Krish PG posted. How can i move it further away from the left margin? Only with width? Usually i use WYSIWYG builders so this is my first personal attemp and still improving :)
@KrishPG yes sure. I only have html knowledge and basic CSS. Never applied them on a project involving php and scripts. I'm happy with this solution for now. Maybe one day i'll learn to design a cool Bootstrap UI. I work as a designer so i'm just trying to expand my knowledge! Thanks you all!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.