PHP Echo Exactly What's Between the 2 Brackets?

Hello, I'm trying to cache some pages.  I want to echo exactly what's between the 2 brackets/notifiers.

Example:

echo [adsfljk 0243r50ih42)(*U_Q*##}@$]
c3jtk
539 jh4804h302h napoh{PIUOH*)T H$
4t 098a
2498098nb;s''''"""";;3q-p40otk-k-qaigjm43p2mnti8qhaesogasgjdkm;lkasf
asf
echo print
6546+40+238945
2
substr()234lksnadnfg;lk
"''';;;;:];

Wow.... That was fun!  Ha.. I'm basically trying to not let anything throw off what I want outputted.  Is there a way to do this?  Thanks.

smoothcat11Asked:
Who is Participating?
 
nizsmoDeveloperCommented:
No i'm afriad thats the only way I know to echo stuff with " character, as you have to escape this character.

There is a function which automatically adds escape characters:

addslashes($somevariable);

Basically if you have a string "she said"this"" then the function would output "she said \"this\"".

That is the closest thing I can think of which may be of help.
0
 
nizsmoDeveloperCommented:
echo "adsfljk 0243r50ih42)(*U_Q*##}@$]
c3jtk
539 jh4804h302h napoh{PIUOH*)T H$
4t 098a
2498098nb;s''''\"\"\"\";;3q-p40otk-k-qaigjm43p2mnti8qhaesogasgjdkm;lkasf
asf
echo print
6546+40+238945
2
substr()234lksnadnfg;lk
\"''';;;;:";
0
 
nizsmoDeveloperCommented:
Hope that worked, did it in a hurry but double checked it now and should work.

let me know how you go :)
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
frindoCommented:
What nizsmo did is he escaped all of the double quotation marks (") and single quotation marks ('). You have to make sure you do that if you want to echo text. That is pretty much the only restriction.
0
 
smoothcat11Author Commented:
Is there any other solution?  I have  a lot of code to echo and it would be easier to do w/out the escape.  Just a symbol that you suround with.  It's weird that they don't have that... even a function.

keep_exact("$string");

Can you think of anything or is the escape it?  Thanks for your time...
0
 
hernst42Commented:
You can use HEREdoc style http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

echo <<<TEXT
adsfljk 0243r50ih42)(*U_Q*##}@$]
c3jtk
539 jh4804h302h napoh{PIUOH*)T H$
4t 098a
2498098nb;s''''\"\"\"\";;3q-p40otk-k-qaigjm43p2mnti8qhaesogasgjdkm;lkasf
asf
echo print
6546+40+238945
2
substr()234lksnadnfg;lk
\"''';;;;:
TEXT;

You only need to care about $ in this case, as the $ is used for variable replacement. So $a will not print $a it will print the content of $a;
0
 
hernst42Commented:
ignore the escape \" the will come out as \" (copied the wrong example text :-( )
0
 
Mark GilbertSenior Performance EngineerCommented:
Use stripslashes() to remove any escaped quotes.
0
 
jeffreydnCommented:
Howabout using quotemeta() to escape any of the possibly offensive characters?
http://us3.php.net/manual/en/function.quotemeta.php

You may want to put the text in a <pre></pre> html tag so that it doesn't get interpreted as HTML, etc. You may want to enforce a wordwrap() depending on your input/output needs. http://us3.php.net/manual/en/function.wordwrap.php

If not, then maybe use htmlspecialchars() to echo out the html reserved characters.

The other idea I had, which is not a great one, is to construct the php and html like so...

<?php if ($var > 1) {    ?>
Text here shows up only if var is greater than 1.
This can go on and on and on...
<?  }  ?>

I would not necessarily recommend that, but it might be the best soln for you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.