Html tags in echo string? I wish to concatenate string, then have tags after each concatenated string. Can I?

// I have many functions adding to the string, after which I wish to echo the //error
//The tags are not appearing as text, yet not formating output
// please advise

if ($first_name = "" || empty($first_name))
	$_Error_Message = "<h1>Please enter your name <br> </br> <br /> </h1>";
	if ($first_name != "")
		$pattern = "/^[a-zA-Z0-9\_]{2,20}/";
		if (!preg_match($pattern,$first_name))
		$_Error_Message .= 'Your Name can only contain _, 1-9, A-Z or a-z 2-20 characters long.<br />';

// then after many functions

echo   $_Error_Message;

Your second message will not concate without the first error message. I would try putting $_Error_Message = ''; at the top of the page. Although this may not be your problem.

There is absolutely nothing wrong with your current code.

Of course tags won’t appear, but they should format the text.

There are two possible errors in your code:

  • either the conditional logic is wrong, and the resulting message just don’t contain any tags
  • or there is some weird post-processing that strips tags from your output

Learn to check your premises before asking a question. It is not that hard to isolate your alleged problem and test to see whether your assertion is true or not.

Just make a test file that contains only three lines

$_Error_Message = "<h1>Please enter your name <br> </br> <br /> </h1>";
echo $_Error_Message;

and run it.
It also worth to check the page source in your browser.

Of course, you will find your HTML tags all right. Which will prove that your problem is somewhere else.

Difficult to comment on why that might be without seeing the surrounding HTML and CSS which might all affect how the formatting tags are, well, formatted. As @colshrapnel said, check the page source and see if that helps.

The <br> </br> <br /> in your h1 tag are a bit odd. Why are you using 3 different forms, one of which is invalid? Better not to use the <br> tag at all and add padding-bottom or margin-bottom in your stylesheet.


I am using different forms of the same tag attempting to find something that works. I was told that the new html require a closing slash /</>. Have not added CSS as of yet attempting to have the php logic & form working prior to doing so.
Should I be able to have a variable = “something something ‘’ html tag html tag ”.concatenate variable .= an additional (tag) html tag “” and have the tags recognized by the browser?
I am coming from a “C” enviroment, new to php, I did html many years ago, while pages were static.
Please note that I placed tags in my reply they are not visiable nor did they advance the line.

Show the resulting page’s HTML source. Without seeing it, any further conversation won’t make any sense.

1 Like

XHTML uses a trailing /; HTML doesn’t, and a leading / is invalid.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.