I have a comma delineated string from an html form:
"wind, sun, ocean, lake"
i can use explode to turn it into an array but what i want to do is take each word and assign it to it's own variable (The number of words in the string may change), to end up with this:
$word1 == 'wind'
$word2 == 'sun'
$word3 == 'ocean'
$word4 == 'lake'
The reason is that I want to be able to put each variable into a single mysql query that cross references all the words at once.
Thanks!
7 2323
Could use just put all the words into an array, then just count how many values you have in the array and use each one as you need it? You know what I mean, that is almost what you are doing with $word1, $word2 and so on. Put everything into the $word array and then use count() to see how many you have and then call each one with something like $word[$c].
cool.. Thanks guys!
I've been reading up on extract() and i think i understand what is happening.. but.. what is a "local symbol table"?
pbmods 5,821
Recognized Expert Expert
Heya, bugboy.
A symbol is a variable, function or class name.
In other words, when you use a variable, function or class:
PHP looks up the symbol ('$someVar') in its table of existing symbols to find the [location in memory of the] value of the variable with that name.
If the symbol hasn't been defined yet, PHP throws an error of E_NOTICE severity.
There are multiple symbol tables; each represents a scope. For example: -
$global = 'not available to example()';
-
-
function example( $var1 , $var2 )
-
{
-
$var3 = ' some value ';
-
-
return $var1 . $var3 . $var2;
-
}
-
example()'s symbol table contains $var1, $var2 and $var3, but not $global.
Meanwhile, the global symbol table contains $global, but not $var1, $var2 nor $var3.
Note that this only applies to variables; functions and classes are always available anywhere after they've been defined.
Wow, thanks pbmods!
So the 'global symbol table' is available to the whole page and a super global is available across multiple pages?
Can i add a value to the superglobal(?) symbol table that has a multi page scope without a form submit?
pbmods 5,821
Recognized Expert Expert
Heya, bugboy.
Not quite. Both superglobals and globals are available to the global scope of every script for a given page load. The difference is that superglobals can be used anywhere, whereas globals are only available in the global scope or by using the $GLOBALS superglobal (or the global keyword).
Here are a couple of examples:
$_SESSION is a superglobal: -
echo $_SESSION['key']; // Works
-
-
function doSomething()
-
{
-
echo $_SESSION['key']; // Also works.
-
}
-
On the other hand, $someVar is just a regular global: -
$someVar = 5;
-
-
echo $someVar; // Works
-
-
function dontDoAnything()
-
{
-
echo $someVar; // Doesn't work.
-
}
-
-
function doSomething()
-
{
-
global $someVar;
-
-
echo $someVar; // Works.
-
}
-
-
function doSomethingElse()
-
{
-
echo $GLOBALS['someVar']; // Works; note that $GLOBALS is a superglobal.
-
}
-
-
function orYouCouldDoThis()
-
{
-
$someVar =& $GLOBALS['someVar']; // Note that this is identical to "global $someVar;"
-
-
echo $someVar; // Works.
-
}
-
Thanks pbmods, i really appreciate all your help and explanations. It helps immensely with not only what to do but why.
BugBoy
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: mr_burns |
last post by:
Hi there,
I have a text box that I will use to search a database. I would like
to use it so that it will not use a whole string (ie. 'red striped
top') but instead break it up into individual words (ie. 'red',
'striped', 'top') and maybe put it into and array. I will then use the
words in the array to search the database.
How do I break a string up this way?
|
by: Brian Kazian |
last post by:
Here's my problem, and hopefully someone can help me figure out if there is
a good way to do this.
I am writing a program that allows the user to enter an equation in a text
field using pre-existing variables. They then enter numerical values for
these variables, or can tell the program to randomize the values used within
a certain bounds. My problem is taking in this equation they have written
in the text field and converting it into...
|
by: Aaron |
last post by:
string a = "i have an apple";
i want the output to be "I Have An Apple";
i was able to capitalize the first word but can't figure out how to
capitalize every word in that string
Thanks,
Aaron
|
by: derrick |
last post by:
I used to program text RPG's in C back in high school, but I was very crude
at it and only learned what I needed to get the job done. I am now about to
graduate college with a degree in English and have had an interest in the
structure of language. In order to begin with my little program, I need to
be able to take a string like "The dog jumped." and be able to take the
first word from the sentence and assign it to a string, such as word1,...
|
by: Alex |
last post by:
Hello,
does anybody know how to turn off the autocomplete feature for a certain
text field?
I am aware of the "autocomplete" attribute, but I have seen other
implementions achieving it without any such attribute and am wondering
whether there is another way to do it .... like via CSS or a naming
convention or .......
| |
by: Maya |
last post by:
Hello guys,
Is there an easy way to extract individual words that form a string and
store them in variables like in this example:
String "how are you?"
My result would be:
var1 = "how"
|
by: J |
last post by:
anybody know a vb.net command to populate an array with each word in a
string? for example " hi how are you"
array(0) = hi
array(1) = how
array(2) = are
array(3) = you
i know i could loop though and search for spaces and build it that way...but
a built in command would be great.
|
by: Jim Carlock |
last post by:
Looking for suggestions on how to handle bad words that might
get passed in through $_GET variables.
My first thoughts included using str_replace() to strip out such
content, but then one ends up looking for characters that wrap
around the stripped characters and it ends up as a recursive
ordeal that fails to identify a poorly constructed $_GET
variable (when someone hand-types the item into the line and
makes a simple typing error).
|
by: Ramper |
last post by:
I need to Write a function that will, given an input string containing many words, split that string into individual words. For each word, the function should output the word, its starting index in the string, and its length to the console without using stream extraction operator.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string sval = " The quick brown fox jumps over the lazy dog";
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |