How to Center in PHP

104 235
    • 1). Set up your text editing software to permit entering and saving a straight text file. If you are using Notepad on Microsoft Windows, no configuration is necessary as it works with straight text by default. If you choose to use an Apple Mac system's "TextEdit," the program must be set correctly for use with this article. Start TextEdit. Select "Preferences" from the "Application" menu, then click the "Plain Text" radio selector for the "New Document Format" category. In the "Saving" section of the configuration screen, click the checkbox to turn off "Append '.txt' extension to plain text files." Under "Rich Text" click the checkbox to select (turn on) the option labeled "Ignore rich text commands in HTML files." Turn off wrapping by clicking on the checkbox to deselect "Wrap to Page" to complete TextEdit setup. Save the changes and open a new document. If using Notepad, open it now. It is under the "All Programs\Accessories" menu when clicking on the Windows start button.

    • 2). Create a new HTML file into which the PHP command will be entered. A basic HTML file must include the following, in order: <html><head><title>My Page Title Here</title></head><body></body></html>

    • 3). Set up the location where the PHP command will go. Every PHP command begins with an opening tag and a closing tag. The opening tag can be either <? or <?php and the closing tag is always: ?> If placed on one line, a complete open and close would appear as follows: <?php ?> Place this between the <body> and the </body> tags of the HTML document.

    • 4). Enter a line of PHP between the open and closing tags that prints a large bold heading at the top of the browser page and centered. To do so, you must use the PHP command "echo", then a quotation mark, followed by the HTML and text information, then finished with a closing quotation mark and a semicolon. An example that creates a large bold header centered at the top of the browser screen that reads "My First Centered PHP Header" (including opening and closing program tags) would appear as such: <?php echo "<center><h1>My First Centered PHP Header</h1></center>"; ?> If you are unfamiliar with HTML, the <h1> tag turns on large bold header and </h1> turns off large bold header.

    • 5). Add more information to the PHP code chunk if desired. If you would like to have an image centered below the header of the page, and you have the image named "mycat.jpg" stored in an "images" directory that resides in the same directory into which the HTML file containing the PHP code will be stored, it may be added so the complete PHP code chunk appears as follows: <?php echo "<center><h1>My First Centered PHP Header</h1><img src="images/mycat.jpg"></center>"; ?>

    • 6). Save the entire file to your Web server directory so it will be able to process it when visitor loads it into the browser. Save it with any name desired, but be certain to save it with a .php extension at the end of the name. An example would be: headerwithimage.php

    • 7). Point your Web browser to the file to view the processed result. If your web address is http://www.mysite.com and the file was saved in the top directory (the one containing the "images" directory as in this example) then you would enter: http://www.mysite.com/headerwithimage.php Providing no typing mistakes were made, the header will appear centered at the top of the page, and the image will appear directly below the header, also centered.

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.