We help IT Professionals succeed at work.

PHP Echo Exactly What's Between the 2 Brackets?

smoothcat11
smoothcat11 asked
on
421 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.

Comment
Watch Question

Joe WuDeveloper | Solutions Architect | CTO
CERTIFIED EXPERT

Commented:
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
\"''';;;;:";
Joe WuDeveloper | Solutions Architect | CTO
CERTIFIED EXPERT

Commented:
Hope that worked, did it in a hurry but double checked it now and should work.

let me know how you go :)

Commented:
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.

Author

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...
Top Expert 2007

Commented:
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;
Developer | Solutions Architect | CTO
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Top Expert 2007

Commented:
ignore the escape \" the will come out as \" (copied the wrong example text :-( )
Mark GilbertSenior Performance Engineer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.