The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> 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
 
Reply to this topicStart new topic
Replies
Brian Chandler
post Mar 5 2012, 01:11 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
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]'.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


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: 29th March 2024 - 04:54 AM