Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Post Installation Help
Author Message
bavarian
Hangin' Around


Joined: Nov 11, 2004
Posts: 25

PostPosted: Mon Oct 15, 2007 5:05 am Reply with quote

trying to get a script to work where a language constant (usually seen in phpNuke as ._XXXXX. is put into HTML code through a variable

something like this ...

Code:
$byttext = strtoupper($altlang);

$byt = "._$byttext.";
         
echo "<a href=\"index.php?newlang=$tl\">
<img src=\"images/language/flag-$tl.png\"  title=\"$byt\"></a>";


the variable $byt is on the page then shown as "._XXXXXX." without the quotes and where XXXXXX is the name of the constant everything is about. to get the value of the constant, I know I should put quotation-marks somewhere .... BUT WHERE? been trying for hours to get the quotation-marks in right place .... without success. any hints are very appreciated, please help ! THANK YOU VERY MUCH IN ADVANCE !
 
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9449
Location: Arizona

PostPosted: Mon Oct 15, 2007 5:43 am Reply with quote

Is this really nuke? If so, you simply add a new define in the appropriate lang-yourlanguage.php file within the languages directory and then use that constant.

So, for example, maybe you have added the following:

define('_XXXXXX', 'This was my label');

The above would have gone in your language file.

Then, to use that define, you would do something like this:
Code:


echo "<a href=\"index.php?newlang=$tl\">
<img src=\"images/language/flag-$tl.png\"  title=\"" . _XXXXXX . "\"></a>";


This should give you what you need.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
bavarian
PostPosted: Mon Oct 15, 2007 6:06 am Reply with quote

yes, that's how it usually works ....

and dependent on the content of the variable (xxx1, xxx2, xxx3 and so on) i need to call the defined constants from the different langauge.php files ...

define("_XXX1","xxx1);
define("_XXX2","xxx2);
define("_XXX3","xxx3);
.
.
.

I got things to work to a certain degree. but the last "touch" is missing ... the quotation-marks

instead of having the code like this

Code:
 title=\"" . _XXXXXX . "\


i have it like this

Code:
title=\"$byt"\


this will return the content of the variable as a text-string. that's ok, but in order to have this recognized as the language constant i need to have quotation-marks around the string. and that's were the problem arises and the code does not work any longer ... whereever i try to put the quotationmarks in my attempts to resolve this
 
montego
PostPosted: Mon Oct 15, 2007 6:24 am Reply with quote

Ok, you must have your reasons for wanting to do it that way. I have defined new constants using dynamically generated constant names, but I have not done the reverse.

Constants are handled a bit differently and so I am not sure you can do this. My initial thought was you may need to wrap it in an eval(), but I have not tried.

You may have better luck if you use a language array rather than constants. Arrays are faster than constant definitions anyways.
 
Gremmie
Former Moderator in Good Standing


Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Mon Oct 15, 2007 8:00 am Reply with quote

bavarian, if you are seeing XXXX instead of the constant's value, then it is likely that the constant wasn't defined in the scope you tried to use it. You may not be including the right language constant file. You might want to turn on warnings so you can see if that is happening.

You may also just try this:

$myVar = _XXXXX;
echo $myVar;

If you see _XXXXX instead of the value for _XXXXX it isn't in scope for some reason.

_________________
Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module 
View user's profile Send private message
Gremmie
PostPosted: Mon Oct 15, 2007 9:25 am Reply with quote

Let me clarify what I said, above. I am assuming you have your constants in another file. Is this correct? Then make sure you have included or required that file in your main script where you are trying to use your constants.

If the file containing the define for the constant XYZ has not been included, then for something like this:

$foo = XYZ;

PHP will issue a notice that XYZ is not defined (which you may not see because of your warning levels), but $foo will get the value of 'XYZ'. That might explain the behavior you are seeing.

Now if you had the file that had the define for XYZ included, PHP will assign the value of XYZ to $foo.
 
bavarian
PostPosted: Mon Oct 15, 2007 10:46 am Reply with quote

Gremmie: yes, the constants are residing in the phpnuke content management system original /language/folder in the root directory. I have already been checking if the constant (just for example here called _XXXX1 with a value of xxxxx1) does return the correct value, if i call it by other means: and yes, it does return the correct value (here for example reason just called xxxx1)

the problem is: in the title-tag that I mentioned above, on the page it just returns exactly as typed in next row

._XXXX1.

which is the name of the constant. that's how far I have manage to get the code to work.

if i remove the variable $XXXX1 and replace it in the title tag with the constant (title=\""._XXXX1"\" )it does then on the page provide everything correctly, the value xxxx1 . even that proofes that the constant from the correct lang.php-file is picked up correctly....

so ... I would need to find a way to put the variable $XXXX1 (that contains the string ._XXXX1. ) into quotationmarks ... that's what I have not succeeded with ! that's where I need help ... so the complete string contained in the constant $XXXX1 would be (including the quotationmarks)

"._XXXX1." (until now, the code just returns only ._XXXX1. without the quotes)

if you guys check in your php-nuke systems and search for files containing code like title=\"$ you will see that there are plenty of files with instances of that. in my case there is a varible that contains the string that is a name of a constant ._XXXX1. if somebody could hint me on how to put that into quotationmarsk the correct way everything could be solved i guess.

title=\""$XXXX1"\" will ruin the code, does give an error ...

also trying to combine the quotationmarks with the string that gives the constant name like

$XXXX1 = ""._XXXX1.""; will ruin the code, provides an error ...
 
fkelly
Former Moderator in Good Standing


Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Mon Oct 15, 2007 12:18 pm Reply with quote

<?php
define (_xxxx, "\"XXXX\"");
$xxxx = _xxxx;
echo $xxxx;

?>
 
View user's profile Send private message Visit poster's website
Gremmie
PostPosted: Mon Oct 15, 2007 1:28 pm Reply with quote

I'm probably not understanding you, but again, that tells me in the place where the variable is assigned the constant, the constant isn't defined, and the variable is getting the constant name instead of the constant value.

It would help if we could see all of the code. Maybe you could zip it up and post a link to it.
 
montego
PostPosted: Tue Oct 16, 2007 5:34 am Reply with quote

Like I said, I don't think it can be done. Constants are handled differently than variables, which is why I suggested using an array for your labels rather than defines.

The key here is that you are trying to dynamically reference a constant. I.e., the constant NAME is dynamically generated for the one that you wish to use at any particular point in time.

I just cannot figure out why you would need for the constant names to be dynamically generated. Never seen that done anywhere in nuke or any other PHP program... ever.
 
Gremmie
PostPosted: Tue Oct 16, 2007 7:01 am Reply with quote

LOL...I'm still totally confused about this and would love to see all of the code in question.

In the meantime, much to my surprise, you can obtain the value of a constant if you don't know its name:
Only registered users can see links on this board! Get registered or login!

Quote:

constant() is useful if you need to retrieve the value of a constant, but do not know its name. I.e. it is stored in a variable or returned by a function.
 
montego
PostPosted: Tue Oct 16, 2007 7:07 am Reply with quote

Gremmie, awesome find! That might be exactly what the Dr. ordered!

worship
 
fkelly
PostPosted: Tue Oct 16, 2007 7:34 am Reply with quote

Quote:
so ... I would need to find a way to put the variable $XXXX1 (that contains the string ._XXXX1. ) into quotationmarks ... that's what I have not succeeded with ! that's where I need help ... so the complete string contained in the constant $XXXX1 would be (including the quotationmarks)

"._XXXX1." (until now, the code just returns only ._XXXX1. without the quotes)


I guess it's the sea air that's keeping me from understanding. The code I quoted does what you are asking for, no? Ummm, looking at it again or is that you want the ._ in there too and the closing . too?
 
fkelly
PostPosted: Tue Oct 16, 2007 7:51 am Reply with quote

In which case:

Code:
<?php

  define (_xxxx, "\"._XXXX.\"");
  $xxxx = _xxxx;
  echo $xxxx;
 
?>


Does the trick.
 
bavarian
PostPosted: Tue Oct 16, 2007 11:34 am Reply with quote

busy days at the moment. will write more on this issue at the end of the week. thanks for the input so far !
 
montego
PostPosted: Wed Oct 17, 2007 5:18 am Reply with quote

fkelly, I believe it is the constant name itself that he wishes to be "dynamic". In other words, some code will figure out which constant to use but the name of that constant is in a variable. Then, he wants to actually reference the constant from that variable to get its value to use elsewhere in his code.

At least that is how I am interpreting the conversation thus far.
 
fkelly
PostPosted: Wed Oct 17, 2007 8:14 am Reply with quote

Well then the answer is found on the user contributed notes section of the page Gremmie sited. Here's my simplified example based on that:

Code:
<?php

 // z determines which constant to use; could be retrieved from a database or based on user input
 $z = '_yyyy';
  define (_xxxx, "\"._XXXX.\"");
   define (_yyyy, "\"._YYYY.\"");
     $xxxx = _xxxx;
  echo constant($z);
 
?>
 
montego
PostPosted: Wed Oct 17, 2007 6:54 pm Reply with quote

Very cool... didn't know the function even existed. Thanks Gremmie for the "find"!
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Post Installation Help

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©