Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP Echo Exactly What's Between the 2 Brackets?

Posted on 2007-10-10
9
Medium Priority
?
383 Views
Last Modified: 2013-12-13
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.

0
Comment
Question by:smoothcat11
9 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20054492
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20054598
Hope that worked, did it in a hurry but double checked it now and should work.

let me know how you go :)
0
 
LVL 3

Expert Comment

by:frindo
ID: 20054615
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:smoothcat11
ID: 20054882
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
 
LVL 48

Expert Comment

by:hernst42
ID: 20054904
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
 
LVL 21

Accepted Solution

by:
nizsmo earned 1200 total points
ID: 20054908
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
 
LVL 48

Expert Comment

by:hernst42
ID: 20054909
ignore the escape \" the will come out as \" (copied the wrong example text :-( )
0
 
LVL 18

Assisted Solution

by:Mark Gilbert
Mark Gilbert earned 800 total points
ID: 20069360
Use stripslashes() to remove any escaped quotes.
0
 
LVL 2

Expert Comment

by:jeffreydn
ID: 20071505
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question