The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Make everything in the variables value not relevant to the rest of the page?
allenph
post Mar 4 2012, 06:45 PM
Post #1


Novice
**

Group: Members
Posts: 21
Joined: 15-February 12
Member No.: 16,477



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!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
allenph
post Mar 4 2012, 08:10 PM
Post #2


Novice
**

Group: Members
Posts: 21
Joined: 15-February 12
Member No.: 16,477



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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Mar 5 2012, 01:11 AM
Post #3


Jocular coder
********

Group: Members
Posts: 2,242
Joined: 31-August 06
Member No.: 43



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]'.



--------------------
Brian Chandler
Nothing in this post constitutes "commercial solicitation". PayPal does not solicit residents of Japan. Contents may settle in transit. "Legal mind" may or may not be brain-damaged.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 24th October 2014 - 01:47 PM