[PHP] PHP arrays and javascript

2004-11-26 Thread Nick Peters
Hey,

i know this probally a simple question, but it has been stumping me for
quite some time now. How do i pass a php array to a javascript?

i tryed:

var myarray = new Array(<?PHP echo $myarray; ?>);


but it didn't work. Anybody got any ideas?

thanks in advance.
-- 
-Nick Peters

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP arrays and javascript

2004-11-29 Thread Nick Peters
Marek Kilimajer wrote:

> Nick Peters wrote:
>> Hey,
>> 
>> i know this probally a simple question, but it has been stumping me for
>> quite some time now. How do i pass a php array to a javascript?
>> 
>> i tryed:
>> 
>> var myarray = new Array(<?PHP echo $myarray; ?>);
>> 
>> 
>> but it didn't work. Anybody got any ideas?
>> 
>> thanks in advance.
> 
> For integers and floats:
> 
> var myarray = new Array();
> 
> For strings:
> 
> var myarray = new Array( ?>);

Would this work the same for multidimensional arrays?

-- 
-Nick Peters

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP arrays and javascript

2004-11-30 Thread Nick Peters
Hodicska Gergely wrote:

>  trigger_error('Hoppa, egy új típus a PHP-ben?
> '.__CLASS__.'::'.__FUNCTION__.'()!', E_USER_WARNING);

on that line, what is the error you are trying to catch? I can't read what
ever language that is ;-) thanks.
-Nick Peters

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP arrays and javascript

2004-11-30 Thread Nick Peters
Hodicska Gergely wrote:

> Hi!
> 
>  > Would this work the same for multidimensional arrays?
> Encoding was a special feature needed by me, maybe you don't need it.
> Usage:
> myArray = array(...);
> echo ''.arrayToJsArray($myArray, 'myArray').'';
> 
> Felho
> 
> --- 8< --- arrayToJsArray.php --- 8< ---
>   function valueToJsValue($value, $encoding = false)
>  {
>  if (!is_numeric($value)) {
>  $value = str_replace('\\', '', $value);
>  $value = str_replace('"', '\"', $value);
>  $value = '"'.$value.'"';
>  }
>  if ($encoding) {
>  switch ($encoding) {
>  case 'utf8' :
>  return iconv("ISO-8859-2", "UTF-8", $value);
>  break;
>  }
>  } else {
>  return $value;
>  }
>  }
> 
>  function arrayToJsArray( $array, $name, $nl = "\n", $encoding =
> false ) {
>  if (is_array($array)) {
>  $jsArray = $name . ' = new Array();'.$nl;
>  foreach($array as $key => $value) {
>  switch (gettype($value)) {
>  case 'unknown type':
>  case 'resource':
>  case 'object':
>  break;
>  case 'array':
>  $jsArray .= arrayToJsArray($value,
> $name.'['.valueToJsValue($key, $encoding).']', $nl);
>  break;
>  case 'NULL':
>  $jsArray .= $name.'['.valueToJsValue($key,
> $encoding).'] = null;'.$nl;
>  break;
>  case 'boolean':
>  $jsArray .= $name.'['.valueToJsValue($key,
> $encoding).'] = '.($value ? 'true' : 'false').';'.$nl;
>  break;
>  case 'string':
>  $jsArray .= $name.'['.valueToJsValue($key,
> $encoding).'] = '.valueToJsValue($value, $encoding).';'.$nl;
>  break;
>  case 'double':
>      case 'integer':
>  $jsArray .= $name.'['.valueToJsValue($key,
> $encoding).'] = '.$value.';'.$nl;
>  break;
>  default:
>  trigger_error('Hoppa, egy új típus a PHP-ben?
> '.__CLASS__.'::'.__FUNCTION__.'()!', E_USER_WARNING);
>  }
>  }
>  return $jsArray;
>  } else {
>  return false;
>  }
>  }
> ?>
> --- 8< --- arrayToJsArray.php --- 8< ---


thanks this works perfect! 
-- 
-Nick Peters

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How to Add a Module

2004-12-02 Thread Nick Peters
Hey,

i currently have a apache and php installed perfectly on my box (slackware
10). However, i have the need to use mcrypt. I have mcrypt all compiled and
installed, but how do i add the module to my php install? I have searched a
few places on the net and i can't figure it out. Thanks in advance.

-- 
-Nick Peters

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to Add a Module

2004-12-03 Thread Nick Peters
Richard Lynch wrote:

> Nick Peters wrote:
>> i currently have a apache and php installed perfectly on my box
>> (slackware 10). However, i have the need to use mcrypt. I have mcrypt all
>> compiled and
>> installed, but how do i add the module to my php install? I have searched
>> a
>> few places on the net and i can't figure it out. Thanks in advance.
> 
> If you compiled from source, go back to your PHP source directory, and do:
> 
> ./config.nice --with-mcrypt
> 
> This should copy all your old settings, which were stored in 'config.nice'
> from the last time, but tack on --with-mcrypt for you this time.
> 
> If you installed from an RPM or whatever Slackware uses for package
> management, then you have just stumbled across the main downfall of
> packages:  Whomever makes the Slackware PHP package thinks you don't need
> mcrypt and you are stuck with starting over compiling PHP from source to
> get what you want.  Sorry.
> 
> PS While you are at it, you may want to breeze through the manual and see
> if there's anything else you for sure want to play with in the next few
> weeks, and install that too.
> 
> Buut, don't go hog-wild trying to add in a bunch of stuff you might
> want "some day"  --  You'll drive yourself crazy trying to get it all
> installed, and never get to it until you need to upgrade PHP anyway.  "I
> been down that road before"
> 

I install from source, so that's good. after i run ./config.nice
--width-mcrypt, do i have to copy any file to my php dir? Thanks in
advance.

-- 
-Nick Peters

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to Add a Module

2004-12-03 Thread Nick Peters
M. Sokolewicz wrote:

> Nick Peters wrote:
>> Richard Lynch wrote:
>> 
>> 
>>>Nick Peters wrote:
>>>
>>>>i currently have a apache and php installed perfectly on my box
>>>>(slackware 10). However, i have the need to use mcrypt. I have mcrypt
>>>>all compiled and
>>>>installed, but how do i add the module to my php install? I have
>>>>searched a
>>>>few places on the net and i can't figure it out. Thanks in advance.
>>>
>>>If you compiled from source, go back to your PHP source directory, and
>>>do:
>>>
>>>./config.nice --with-mcrypt
>>>
>>>This should copy all your old settings, which were stored in
>>>'config.nice' from the last time, but tack on --with-mcrypt for you this
>>>time.
>>>
>>>If you installed from an RPM or whatever Slackware uses for package
>>>management, then you have just stumbled across the main downfall of
>>>packages:  Whomever makes the Slackware PHP package thinks you don't need
>>>mcrypt and you are stuck with starting over compiling PHP from source to
>>>get what you want.  Sorry.
>>>
>>>PS While you are at it, you may want to breeze through the manual and see
>>>if there's anything else you for sure want to play with in the next few
>>>weeks, and install that too.
>>>
>>>Buut, don't go hog-wild trying to add in a bunch of stuff you might
>>>want "some day"  --  You'll drive yourself crazy trying to get it all
>>>installed, and never get to it until you need to upgrade PHP anyway.  "I
>>>been down that road before"
>>>
>> 
>> 
>> I install from source, so that's good. after i run ./config.nice
>> --width-mcrypt, do i have to copy any file to my php dir? Thanks in
>> advance.
>> 
> not '--width-mcrypt', just '--with-mcrypt' ;)

Sorry, i must learn to think before i type ;-)

but i am still left wondering if i have to copy anythign to my php dir after
running said command.

-- 
-Nick Peters

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php