5

I have a php script that does a query in my database and returns a string ( like "2" ). I print it using

print strip_tags('2');

but in the output of my browser I get :

<body><html>2</html></body>

Is there any way to prevent the tags from beiing printed? Is it maybe that the browser auto adds them?


For all those answering about strip_tags (" 2 ");

THIS IS WRONG:

I want a siple version.php with echo '2';

and nothing else. It prints the tags too. I don't have the tags and then try to print.


More explanation to those who try to get easy rep

my code is:

$str = '2';
print strip_tags($str);

and it prints

<html><head></head><body>2</body></html>
Panos
  • 7,227
  • 13
  • 60
  • 95

2 Answers2

2

It is not possible. The browser creates these elements automatically, without it there would not be any text flow(means nothing of this could be made visible).
You can just use this variable for any script, it won't include the HTML tags. This is only made by the browser to make it visible for you.

nkmol
  • 8,025
  • 3
  • 30
  • 51
1

You can use

header("Content-Type: text/plain");

at the beginning of your script, in order to tell the browsers you're only gonna send plain text, not html. This will prevent your browser from automatically adding those html tags.

Then, check what you print (or echo). Here, the body tag should be in html tag.

OlivierH
  • 3,875
  • 1
  • 19
  • 32
  • It isn't possible. Test your code with the header and see the result. You can't show ANY text in the browser without these tags. Plain text will result in a `
    ` text, which still needs the default HTML tags. See [here](http://stackoverflow.com/questions/1414325/is-headercontent-typetext-plain-necessary-at-all) when to use.
    – nkmol Nov 18 '13 at 09:03