1

I am learning PHP by myself and I wonder if you guys can help me to solve my problem. I want to concatenate 2 variables that are align right in the form of an hyperlink with a word. I can do that no problem, but the word is not getting aligned right as well. I have tried somethings, but it doesnt work. Please see my code:

<?php
     $log = ( '<a style="float:right; "href="login.php">login </a>'  ) ;
     $reg = ( '<a style="float:right; "href="login.php">register </a>' );
     echo $log ." or " .  $reg;
?>

I need login or register to be displayed on the top right of the page, but I dont want to hyperlink the word "or". Also, if you guys have any links for good tutorials on PHP or tutorials on how to create a good website design, maybe templates, please paste here. I am starting with websites now and I am learning by myself. Any help is appreciatted. :-)

2
  • 3
    This does not seem like a PHP issue, sounds more like you need to tweak your CSS to me Commented Mar 13, 2012 at 20:59
  • Any reason you aren't using plain HTML for this? Commented Mar 13, 2012 at 21:36

4 Answers 4

2

You probably are thinking wrong in terms of HTML/CSS markup. HTML code that will be generated by your script looks as follows:

<a style="float:right; "href="login.php">login </a> or <a style="float:right; "href="login.php">register </a>

It will first float "login" to the right, then append "register" to the left of "login". I would suggest doing it this way:

<?php
    $log = '<a href="login.php">login </a>';
    $reg = '<a href="login.php">register </a>';
    echo sprintf("<div style='float:right;'>%s or %s</div>", $log, $reg);
?>
Sign up to request clarification or add additional context in comments.

Comments

2

I would wrap them in a container div thats floated right, float the links left and make the or a span that is floated left as well.

<?php
 $log = ( '<a style="float:left; "href="login.php">login </a>'  ) ;
 $reg = ( '<a style="float:left; "href="login.php">register </a>' );
 echo '<div style="float:right;">'.$log .'<span style="float:left;"> or </span>'.$reg.'</div>';

also, its better to assign classes. you could write all that markup just by assigning a class to the container div

3 Comments

style="float:left; "href="login.php" is incorrect, you need a space before href.
ah, I just copy and pasted his code as its not really pertinent to his actual question.
I assumed it was relevant, because of but I dont want to hyperlink the word "or"... but I fear I may be incorrect. Testing in Firefox proved to be forgiving.
0

Try encapsulating both of your anchor tags in a div tag that is floated to the right.

<?php
     $log = '<a href="login.php">login</a>' ;
     $reg = '<a href="login.php">register</a>';
     echo "<div style='float:right; width:200px;'>$log or $reg</div>";
?>

also, notice how inside of double quotes, you can put a variable as i've done in my echo statement.

1 Comment

Oh i never noticed the incorrect double quotes on the href's. Thanks for the edit.
-1

If you need a CMS try some existing distributions instead of inventing the wheel again.

For templates use something like Mustache or Smarty.

Comments

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.