kamikaze_pilot
kamikaze_pilot

Reputation: 14844

PHP cannot print my string properly

so I have the following code:

$tag = 'script';
$r = '#(<'.$tag.'.*?>).*?(</'.$tag.'>)#';
echo $r;

but then when it echoes, it merely echoes this: #().*?()#

not even the 'script' is being echoed.....and notice that the less than equal sign, etc are not there...

what am I doing wrong?

Upvotes: 0

Views: 366

Answers (3)

Itay Moav -Malimovka
Itay Moav -Malimovka

Reputation: 53607

do view source to see why. It will probbably be:

#(<script.*?>).*?(</script>)#';

Which each browser will display as

#().*?()#

As it hides any XML tags from the parsed view, i.e hides the <script.*?> and the </script> which can be seen, though, in the unparsed version->view source

Upvotes: 4

Warface
Warface

Reputation: 5119

It's because it print

#(<script.*?>).*?(</script>)

It's invisible to the browser but look in the source code, it should be there :D

Upvotes: 1

rockerest
rockerest

Reputation: 10518

If you're printing to HTML or a web browser, it will be ignoring tags it doesn't understand or wouldn't normally display, like <script>. See this jsfiddle for example.

Upvotes: 2

Related Questions