Search code examples
phpoopstaticstyling

In PHP script, nothing between <these brackets> will appear in browser


***EDIT #3 Anyone who down votes this post has issues. Lets not act like we all haven't had a day in which we work so much, that something that should seem obvious, isn't. I genuinely looked for an answer, however, I worked so long that I could no longer think straight. Thanks again to those who helped, but down voting my post is juvenile and unnecessary. I hope I worded my question well enough so that someone searching for this like I was, has an easier time finding the answer before they look as silly as I did. Have a great day.

----------------------------Question Below----------------------------------

I am trying to write a script that will wrap a message with a tag in order to display the message in a specific styling in a command line application. My problem, is that I can't seem to output anything between <these brackets>. I know this is a PHP white belt issue, but my StackOverFlow and Google Fu is weak and pathetic right now and I can't seem to find the reason for my issue. Bellow is my code:

    <?php namespace Acme;

class MessageWrapper
{

    protected static $message;
    protected static $tag;

    public static function wrap($message, $tag)
    {
        self::$message = $message;
        self::$tag = $tag;

        // hides the $tag output, as well as the <>
        //   return "<$tag>" . $message . "<$tag>";

        return $tag . $message . $tag;
    }
}

$message = "Example message";
$tag = "error";
$example = MessageWrapper::wrap($message, $tag);
var_dump($example);

I am at a loss for what the issue is, and I am sure I'll feel like an idiot (if) when someone points out the issue, but I'm tapped out of ideas right now and I'd really like to understand better. Can anyone help a brother out?

EDIT**** In the command line application, it works as intended, however, I do not understand why no output to the browser. If anyone could provide me with some resources to point me in the right direction, much appreciation to you.

EDIT #2: I assume its because its trying to be parsed as HTML. Is there a way to format it in order to see it in the browser anyway?


Solution

  • The browser will parse it as HTML. If you want to see the raw HTML, use htmlspecialchars() to encode it:

    echo htmlspecialchars($example);