Results 1 to 13 of 13

Thread: align center in php

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    align center in php

    echo "<align=center>Logged in successfully.<br>";

    why doesnt that work?

    and also:

    echo "Click here";

    how would i hyperlink the word 'here'

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: align center in php

    1) Align is not an HTML tag, align=center is not valid SGML syntax, and you did not have a closing tag to boot.

    HTML Code:
    <span style="text-align: center;">Logged in successfully</span><br>

    2) The usual way - using an anchor tag. Also, read the Don't say Click Here link in my signature.

    HTML Code:
    <a href="somewhere">Somewhere</a>

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: align center in php

    thanks alot penegate, 1 more question, i wana make the font verdana, size 9, any idea mate?

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: align center in php

    You should have a stylesheet, which is a .css file you attach using a <link> tag in your <head> section.

    HTML Code:
    <head>
      <link rel="stylesheet" type="text/css" href="mypage.css">
    </head>
    In the stylesheet you can put CSS rules such as font etc.
    Code:
    html {
      font: 9pt Verdana, sans-serif;
    }
    sans-serif is a generic font class which is there as a fallback in case Verdana is not available on the user's system.

    All presentational rules should be set in the CSS file. The only things you should have in the HTML document are classes and id's, which you can use in CSS selection rules. If you are not familiar with this I suggest you go through a CSS tutorial.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: align center in php

    oops sorry i meant just the text

    <span style="text-align: center;">Logged in successfully</span><br>

    just that to be verdana, not all 'fonts'

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: align center in php

    Ah,

    You should give that a class (if it will appear more than once on a page) or ID (if it will appear only once).

    Then you can select it in your stylesheet like this:
    Code:
    /* For a class: */
    .classname {
      font: 9pt Verdana, sans-serif;
    }
    
    /* For an ID: */
    #id {
      font: 9pt Verdana, sans-serif;
    }

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: align center in php

    Quote Originally Posted by penagate
    1) Align is not an HTML tag, align=center is not valid SGML syntax, and you did not have a closing tag to boot.

    HTML Code:
    <span style="text-align: center;">Logged in successfully</span><br>

    2) The usual way - using an anchor tag. Also, read the Don't say Click Here link in my signature.

    HTML Code:
    <a href="somewhere">Somewhere</a>
    that centre align is for html but how would it be done in php mate?

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: align center in php

    PHP is a pre-processor. In most cases, and in this case, you're using it to output HTML code. So there's absolutely no difference. Whether you are using PHP or ASP or no server side language is completely transparent to the browser, which is what does the HTML and CSS parsing.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: align center in php

    but my code is like this

    PHP Code:
             <?
                if (empty($Username) || empty($Password)) {
                    echo "You didn't fully input login details. Please go back and try again";
                }

                else {
                    $res = $db->_LOGIN($Username, $Password);
                    
                    if ($res == 1) {
                        echo "Logged in successfully.<br>";
                        echo "Test";
                    }
                        
                    else echo "You specified invalid login details, please go back and try again.";
                }
                
            ?>
    and it throws errors when i put ur code in

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: align center in php

    You probably have to escape the additional quotes, for example:

    PHP Code:
    echo "<span class=\"classNameHere\">Logged in successfully.</span><br>"
    If you do not escape the additional quotes in the text, PHP thinks it's the end of the string and thinks that everything after it is PHP code.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: align center in php

    Don't use double quotes for strings. Single quotes are more efficient and avoids having to escape most characters. Also, don't use echo to output HTML. Output is what PHP does when it's not doing anything, so just stop the PHP block.

    PHP Code:
    <?php if ($res == 1): ?>
      <span style="text-align: center; ">Logged in successfully.</span><br>
    <?php endif; ?>

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: align center in php

    Applying alignment to a span element will not do anything.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: align center in php

    Div then. My mistake, forgot it was inline.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width