Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ Make everything in the variables value not relevant to the rest of the page?

Posted by: allenph Mar 4 2012, 06:45 PM

So what i mean is if i set a variable to "[" ($some_variable = "[") the rest of my code is now going to go CRAZY because there is an open [. Is there a way I can just make everything inside the first set of "" not relevant to the code? thanks!

Posted by: allenph Mar 4 2012, 08:10 PM

QUOTE(allenph @ Mar 4 2012, 06:45 PM) *

So what i mean is if i set a variable to "[" ($some_variable = "[") the rest of my code is now going to go CRAZY because there is an open [. Is there a way I can just make everything inside the first set of "" not relevant to the code? thanks!

Solved on another forum I used htmlentities(); that converts all your weird chars like " to something html can understand but php thinks is just regular chars

Posted by: Brian Chandler Mar 5 2012, 01:11 AM

QUOTE(allenph @ Mar 5 2012, 08:45 AM) *

So what i mean is if i set a variable to "[" ($some_variable = "[") the rest of my code is now going to go CRAZY because there is an open [. Is there a way I can just make everything inside the first set of "" not relevant to the code? thanks!


I'm not sure what you solved, but the above question seems to be a gross misunderstanding.

A variable is like a "box"; it holds a value. In PHP this value can be of various types -- an integer, a floating point number, a string of characters, a boolean (TRUE or FALSE), plus some really confusing stuff like NULL. But whatever value you assign to the variable, that's it: the variable just sits there holding the value. Unless you do something with it -- like copying to another variable, or using as an argument (parameter) to a function, it has no effect on anything else.

So if I write $open = '['; $close = ']'; this makes these variables hold these character values. It does not make anything go crazy.

But note it's generally a good idea to represent string literals with single-quoting, unless you are using the variable replacement thingy, e.g. with $expression = "$open$var=$value$close"; ... possibly making $expression equal to '[name=brian]'.


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)