I want to literally output, with echo, html tags.
First the code was like this:
$image = '[img]'."image_url".'[/img]<BR>';
but that was not working because the output was:
*[img]image_url[/img]*
and then break into new line.
Then I found a solution:
$image = '[img]'."image_url".'[/img]<BR>';
My question is:
Why single quotes don’t literally output string as I thought they would and is there any other way so I don’t have to write all those < and >?
Your problem comes from a fundamental misunderstanding of how PHP and HTML work. The quotes, which are a part of PHP’s syntax, cannot influence how the browser interprets the quoted string because the browser never sees the quoted string. The quotes fall away as the PHP code executes and only the output of your PHP script is sent to the browser.
That said, the quotes aren’t intended to control the interpreting of HTML tags within strings anyways. Quote style is about escape sequences like
\nand\t; single quotes do not support escape sequences (except for\') while double quotes interpret them as literal new lines/tabs/etc. Neither style of quote has anything to do with angle-brackets and HTML tags.If you want the browser to display literal greater than and less than signs, you have to send the browser the encoded HTML entities
>and<respectively. You can do this by manually outputting the strings likeecho ">";, or more commonly, by using one of PHP’s functions specifically intended to encode HTML entities found in strings: