BHWD
BHWD

Reputation: 123

Print HTML & CSS via PHP

I have a user registration and login form which has various error/success messages. I am trying to put my error box html code around each error message but am having a bit of difficulty.

The html for the error box is:

<div class="alert alert-info alert-login"> *error message here* <div>

My PHP looks like this:

$msg = 'login failed';

I have tried the following:

$msg = '<div class=\"alert alert-info alert-login\">login failed<br></div>';

However this did not work, is anyone able to shed some light as to why and how I am able to fix this? The message is showing but the div styling does not. Cheers!

Upvotes: 0

Views: 242

Answers (3)

cavaliercyber
cavaliercyber

Reputation: 234

Because ' can also use for " in html. You can code like this in this case.

$msg = "<div class='alert alert-info alert-login'>login failed<br></div>";

Upvotes: 0

Duncan
Duncan

Reputation: 964

You don't need to use slashes if the apostrophes are different.

$msg = '<div class="alert alert-info alert-login">login failed<br></div>';
       ^           ^

Upvotes: 1

Nicklas Nygren
Nicklas Nygren

Reputation: 2605

Since you're using single quotes to encapsulate the string, you don't need to escape the double ones, so use:

$msg = '<div class="alert alert-info alert-login">login failed<br></div>';

More about strings and single quotes: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

Upvotes: 3

Related Questions