I have the following piece of code (symplified)
require("lang.{ $lang}.inc.php" ); // I include the inc. files
....
function decodify($techn ique) { // functions that give me back the
value in inc.file
switch ($technique) {
case 'C':
echo $charcoal;
break;
case 'O':
echo $oil;
break;
case 'A':
echo $acrylic;
break;
}
}
.....
Somewhere I call the function ....decodify($m yTechnique)
But it doen't print the content from $charcoal, $oil or, etc.
Do I have to declare the function global or something like that. In
that case, how should I do it??
Many thanks. Bettina 9 1818
Hallo Bettina,
What is the exact name of the file you are trying to include. Your construct
is very weird, if the file is "lang.EN.inc.ph p" for example, try:
require("lang.$ lang.inc.php");
Also, could you post the code of that included file so we can see if the
values are really there.
Hope this helps,
DXTrim
<be*****@coaste r.ch> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. . I have the following piece of code (symplified)
require("lang.{ $lang}.inc.php" ); // I include the inc. files ... function decodify($techn ique) { // functions that give me back the value in inc.file switch ($technique) { case 'C': echo $charcoal; break; case 'O': echo $oil; break; case 'A': echo $acrylic; break; } } .... Somewhere I call the function ....decodify($m yTechnique)
But it doen't print the content from $charcoal, $oil or, etc. Do I have to declare the function global or something like that. In that case, how should I do it?? Many thanks. Bettina be*****@coaster .ch wrote: I have the following piece of code (symplified)
require("lang.{ $lang}.inc.php" ); // I include the inc. files ... function decodify($techn ique) { // functions that give me back the value in inc.file switch ($technique) { case 'C': echo $charcoal; break; case 'O': echo $oil; break; case 'A': echo $acrylic; break; } } .... Somewhere I call the function ....decodify($m yTechnique)
But it doen't print the content from $charcoal, $oil or, etc. Do I have to declare the function global or something like that. In that case, how should I do it?? Many thanks. Bettina
You cannot access a variable that is outside of a function unless you
write global $var; inside the function. The other way is to include the
lang file inside the function.
Gvre
Hi DXTrim,
the values are really there since I use the references outside the
function and it work ok. I think it has something to do with what says
Giannis regarding the global variable. I'll try that. Thank you.
DXTrim schrieb: Hallo Bettina,
What is the exact name of the file you are trying to include. Your construct is very weird, if the file is "lang.EN.inc.ph p" for example, try:
require("lang.$ lang.inc.php");
Also, could you post the code of that included file so we can see if the values are really there.
Hope this helps,
DXTrim
<be*****@coaste r.ch> wrote in message news:11******** **************@ g49g2000cwa.goo glegroups.com.. . I have the following piece of code (symplified)
require("lang.{ $lang}.inc.php" ); // I include the inc. files ... function decodify($techn ique) { // functions that give me back the value in inc.file switch ($technique) { case 'C': echo $charcoal; break; case 'O': echo $oil; break; case 'A': echo $acrylic; break; } } .... Somewhere I call the function ....decodify($m yTechnique)
But it doen't print the content from $charcoal, $oil or, etc. Do I have to declare the function global or something like that. In that case, how should I do it?? Many thanks. Bettina
How should I define the global variable inside this function? What must
be global is the lang.{$lang}.in c.php so that it can be read inside the
function, isn't it?. I tried including the lang file in the function
but I receive an error.
require("lang.{ $lang}.inc.php" );
function technique($t) {
switch ($t) {
case 'C':
echo $charcoal;
break;
case 'O':
echo $oil;
break;
case 'A':
echo $acrylic;
break;
}
}
<? technique($myTe chnik ?> be*****@coaster .ch wrote: How should I define the global variable inside this function? What must be global is the lang.{$lang}.in c.php so that it can be read inside the function
require("lang.{ $lang}.inc.php" ); function technique($t) { switch ($t) { case 'C': echo $charcoal; ...
$charcoal is local to your function. You can do it in two ways..
1.
function technique($t) {
global $charcoal;
switch ($t) {
case 'C':
echo $charcoal;
2.
function technique($t) {
switch ($t) {
case 'C':
echo $GLOBAL['charcoal']; be*****@coaster .ch wrote: How should I define the global variable inside this function? What must be global is the lang.{$lang}.in c.php so that it can be read inside the function, isn't it?. I tried including the lang file in the function but I receive an error.
require("lang.{ $lang}.inc.php" ); function technique($t) { switch ($t) { case 'C': echo $charcoal; break; case 'O': echo $oil; break; case 'A': echo $acrylic; break; } }
<? technique($myTe chnik ?>
function technique($t) {
global $lang; // here we are using the global var $lang
$incFile = "lang.{$lang}.i nc.php";
if ( file_exists($in cFile) )
include ($incFile);
else
return;
switch ($t) {
case 'C':
echo $charcoal;
break;
case 'O':
echo $oil;
break;
case 'A':
echo $acrylic;
break;
}
}
Gvre
ps. To OP. You can put all strings in file "lang.{$lang}.i nc.php" in an
array and access it like this. If you do it like this you don't have to
change the function technique($t) every time you put a new var in lang file.
// vars file
$strings = array (
"C" => "charcoal",
"O" => "oil",
"A" => "acrylic"
);
// index ? file
$incFile = "lang.{$lang}.i nc.php";
if ( file_exists($in cFile) )
include ($incFile);
else
return; // or any other action
// functions file
function technique($t) {
global $strings;
if (array_key_exis ts($t, $strings))
echo $strings[$t];
}
Thank you, the first option works ok!
Hallo Giannis, that of putting everything in my lang file so that I
don't have to change the function every time I add a new variable works
fine! Thank you for the tip!
Giannis Vrentzos schrieb: be*****@coaster .ch wrote: How should I define the global variable inside this function? What must be global is the lang.{$lang}.in c.php so that it can be read inside the function, isn't it?. I tried including the lang file in the function but I receive an error.
require("lang.{ $lang}.inc.php" ); function technique($t) { switch ($t) { case 'C': echo $charcoal; break; case 'O': echo $oil; break; case 'A': echo $acrylic; break; } }
<? technique($myTe chnik ?>
function technique($t) { global $lang; // here we are using the global var $lang $incFile = "lang.{$lang}.i nc.php";
if ( file_exists($in cFile) ) include ($incFile); else return;
switch ($t) { case 'C': echo $charcoal; break; case 'O': echo $oil; break; case 'A': echo $acrylic; break; } }
Gvre
ps. To OP. You can put all strings in file "lang.{$lang}.i nc.php" in an array and access it like this. If you do it like this you don't have to change the function technique($t) every time you put a new var in lang file.
// vars file $strings = array ( "C" => "charcoal", "O" => "oil", "A" => "acrylic" );
// index ? file $incFile = "lang.{$lang}.i nc.php"; if ( file_exists($in cFile) ) include ($incFile); else return; // or any other action // functions file function technique($t) { global $strings;
if (array_key_exis ts($t, $strings)) echo $strings[$t];
}
> But it doen't print the content from $charcoal, $oil or, etc. Do I have to declare the function global or something like that. In that case, how should I do it?? Many thanks. Bettina
to combine some of the ideas in this thread...
replace the whole case block with:
echo $GLOBAL[array('C'=>'cha rcoal','O'=>'oi l','A'=>'acryli c')[$technique]];
Bye.
Jasen This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris Herring |
last post by:
Hi there: Well, let me start off by saying that I am a Visual Studio drag
and drop weenie, not a real programmer. So I tend to get confused when
things do not look like the instructions said they were going to look :) .
Here is my current dilemma:
I am having a strange problem with my ASP.NET application. I am building the
application using...
|
by: Paul |
last post by:
Hi,
VB.NET is saying the file I am creating is in use by another process and
won't complete its task of moving the file to the specified destination
folder.
Here is my code (the main bit anyway)....
Private Sub LogChange(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
If e.ChangeType = WatcherChangeTypes.Created Then
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
Hello,
I have a very simple problem but cannot seem to figure it out. I have a
very simple php script that sends a test email to myself. When I...
|
by: Jean-David Beyer |
last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2
V6.1 (with all the FixPacks) on my old machine.
I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat
Enterplise Linux 3 ES, and applied FixPack fp5_mi00069.tar to it. After
creating an instance, starting the database, creating a database, and
entering...
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much appreciated.
Thanks in advance
| |
by: Raed Sawalha |
last post by:
Hello , I have windows service which do listening to specified directory
using FileSystemWatcher , on Created Event and Get all the files in the
directory using Directory.GetFiles function then foreach file in the files
list and passed the file path to a function to read its content then process
it then move it to another directory
am reading...
|
by: Sin |
last post by:
> Xxxxx : error PRJ0008 : Could not delete file 'd:\xxxxxxx.dll'.
> Make sure that the file is not open by another process and is not
write-protected.
>
> LINK : fatal error LNK1168: cannot open ../../Debug/xxxxx.dll for writing
>
> The file 'xxxxxx.dll' cannot be copied to the run directory. The process
cannot
> access the file because it...
|
by: JonSteng |
last post by:
..Net Visual Studio Professional 2003 Version 7.1.3088
..Net Framework 1.1 SP1 Version 1.1.4322
IIS 5.1
Windows XP Professional SP2
Micron T3000 Laptop (1.5 GHz; 1GB RAM; 40GB HD with 17GB Free)
I installed FrontPage server extensions to IIS on my computer while
following instructions in a Microsoft ASP.Net MCSD training book.
After...
|
by: dermot |
last post by:
I have wrriten a small windows service application in visual studio
..net 2003 which listens for incoming FTP files.
These files would overwrite over time due to duplicate file names.
However any time the windows service tries to rename the file (using
flFile.move(source,destination)) it gets an error saying access is
denied.
The files are...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |