Print string in php

I am trying to print the following string in php


But it only prints RQC7. If I remove the character <, then I get the complete string. I do not understand why this is happening. I googled but could not find any answer.

I had to use an image because I could not print the total string in stack overflow either.

Actually this is part of a shared secret, which Client codes will access with $obj->getSharedSecret(); I was just testing the output of the function with var_dump(). If var_dump cannot print the total string, then this wont work to validate input, right?

Regards, TAnvir

3 answers

  • answered 2018-01-14 11:06 Quentin

    You are, presumably, looking at the output in a web browser.

    By default PHP will include a Content-Type: text/html response header, so the browser will try to interpret the result as if it were HTML.

    In HTML < means "Start of tag".

    If you want to include < as data, you need to use a character reference such as &lt; instead.

    Use the htmlspecialchars function to convert your string of text to a string of HTML.

        echo htmlspecialchars('RQC7<lxC; etc etc');

  • answered 2018-01-14 11:06 Butuzov

    It because "<" is tag start, its actually printing string you want but you don't see it in your html. You need to take a look to source or use htmlentities or htmlspecialchars functions. Or if you prefer use var_dump for this kind of printing install xdebug (which will transform string into correct string representation)

  • answered 2018-01-14 11:06 Mohsen Newtoa

    you can use this