No questions, but just consider if this is useful to you:-) but of course
feedback & corrections are welcome.
function php_mixed_to_js_value($jsname, $mixed)
{
if(is_null($mixed))
{ return "\n $jsname = null;\n"; }
elseif(is_string($mixed))
{ return "\n $jsname = '$mixed';\n"; }
elseif(is_numeric($mixed) || is_boolean($mixed))
{ return "\n $jsname = $mixed;\n"; }
elseif(is_array($mixed))
{
$retvalue = "\n $jsname = new Array();\n";
foreach($mixed as $key=>$value)
{
if(is_numeric($key))
$new_jsname = $jsname."[".$key."]";
else
$new_jsname = $jsname."['".$key."']";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
return $retvalue;
}
elseif(is_object($mixed))
{
$retvalue = "\n $jsname = new Array();\n";
$object_vars = get_object_vars($mixed);
foreach($object_vars as $key=>$value)
{
$new_jsname = $jsname."['".$key."']";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
return $retvalue;
}
elseif(is_resource($mixed) && get_resource_type($mixed) == "mysql result"
&& mysql_numrows($mixed)!==false)
{
$retvalue = "\n $jsname = new Array();\n";
$index=0;
while($row = @mysql_fetch_assoc($mixed))
{
$retvalue.= $jsname."['row_nr_".$index."'] = new Array();\n";
foreach($row as $key=>$value)
{
$new_jsname = $jsname."['row_nr_".$index."']['$key']";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
$index++;
}
return $retvalue;
}
} 3 2550
// well i took away some useless stuff and corrected something
// remember to use inside javascript tags!
// <?=php_mixed_to_js_value('names', $names)?>
function php_mixed_to_js_value($jsname, $mixed, $db_assoc=true)
{
if(is_null($mixed))
{ return "\n$jsname = null;\n"; }
elseif(is_string($mixed))
{ return "\n$jsname = '$mixed';\n"; }
elseif(is_numeric($mixed) || is_boolean($mixed))
{ return "\n$jsname = $mixed;\n"; }
elseif(is_array($mixed))
{
$retvalue = "\n$jsname = new Array();\n";
foreach($mixed as $key=>$value)
{
if(is_numeric($key))
$new_jsname = $jsname."[".$key."]";
else
$new_jsname = $jsname."['".$key."']";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
return $retvalue;
}
elseif(is_object($mixed))
{
$retvalue = "\n$jsname = new Array();\n";
$object_vars = get_object_vars($mixed);
foreach($object_vars as $key=>$value)
{
$new_jsname = $jsname."['".$key."']";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
return $retvalue;
}
elseif(is_resource($mixed) && get_resource_type($mixed) == "mysql result"
&& mysql_numrows($mixed)!==false)
{
$retvalue = "\n$jsname = new Array();\n";
$index=0;
if($db_assoc)
{
while($row = @mysql_fetch_assoc($mixed))
{
$retvalue.= "\n".$jsname."[$index] = new Array();\n";
foreach($row as $key=>$value)
{
$new_jsname = $jsname."[$index]['$key']";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
$index++;
}
}
else
{
while($row = @mysql_fetch_row($mixed))
{
$retvalue.= "\n".$jsname."[$index] = new Array();\n";
foreach($row as $key=>$value)
{
$new_jsname = $jsname."[$index][$key]";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
$index++;
}
}
return $retvalue;
}
}
// HOPEFULLY LAST CORRECTED VERSION :-)
function php_mixed_to_js_value($jsname, $mixed, $db_assoc=true)
{
if(is_null($mixed))
{ return "\n$jsname = null;\n"; }
elseif(is_string($mixed))
{ return "\n$jsname = '$mixed';\n"; }
elseif(is_numeric($mixed))
{ return "\n$jsname = $mixed;\n"; }
elseif($mixed===true)
{ return "\n$jsname = true\n"; }
elseif($mixed===false)
{ return "\n$jsname = false;\n"; }
elseif(is_array($mixed))
{
$retvalue = "\n$jsname = new Array();\n";
foreach($mixed as $key=>$value)
{
if(is_numeric($key))
$new_jsname = $jsname."[".$key."]";
else
$new_jsname = $jsname."['".$key."']";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
return $retvalue;
}
elseif(is_object($mixed))
{
$retvalue = "\n$jsname = new Array();\n";
$object_vars = get_object_vars($mixed);
foreach($object_vars as $key=>$value)
{
$new_jsname = $jsname."['".$key."']";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
return $retvalue;
}
elseif(is_resource($mixed) && get_resource_type($mixed) == "mysql result"
&& mysql_numrows($mixed)!==false)
{
$retvalue = "\n$jsname = new Array();\n";
$index=0;
if($db_assoc)
{
while($row = @mysql_fetch_assoc($mixed))
{
$retvalue.= "\n".$jsname."[$index] = new Array();\n";
foreach($row as $key=>$value)
{
$new_jsname = $jsname."[$index]['$key']";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
$index++;
}
}
else
{
while($row = @mysql_fetch_row($mixed))
{
$retvalue.= "\n".$jsname."[$index] = new Array();\n";
foreach($row as $key=>$value)
{
$new_jsname = $jsname."[$index][$key]";
$retvalue.= php_mixed_to_js_value($new_jsname, $value);
}
$index++;
}
}
return $retvalue;
}
}
*** Perttu Pulkkinen wrote/escribió (Fri, 01 Oct 2004 14:44:53 GMT): // HOPEFULLY LAST CORRECTED VERSION :-)
What does this function do?
--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike Kamzyuk |
last post by:
Hello all. Basically, I need to call a mixed-mode dll's function
(which uses managed code) from a native or mixed-mode dll function
(which does not use managed code). I'm wondering if this could...
|
by: Steve Terepin |
last post by:
I've found some rather worrying articles (Mixed Mode Library Assembly bug,
Richard Grimes, Windows Developer Network Sept 2003 ; and Knowledge Base
Article 814472 ) that point out the need to use...
|
by: Edward Diener |
last post by:
I received no answers about this the first time I posted, so I will try
again. My inability to decipher an MSDN topic may find others who have the
same inability and someone who can decipher and...
|
by: Bern McCarty |
last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains
other than the default AppDomain? Is there any means at all of doing this?
Mixed-mode is incredibly convenient, but if I...
|
by: AG |
last post by:
Hi,
I have implemented the ASP.Net Ihttphandler interface. Handler references
the mixed dll (both managed/unmanaged code) that contains core C++ classes
wrapped under managed c++ wrappers....
|
by: Lonewolf |
last post by:
hi,
I'm still in the process of transiting from MFC/VC6 to vs2005, and a
lot of things are very alien to me. So hope you could bear with me if my
question sounds stupid. Basically I have native...
|
by: comp.lang.tcl |
last post by:
I wrote this PHP function in the hopes that it would properly use a TCL
proc I wrote about 4 years ago:
if (!function_exists('proper_case')) {
/**
* Ths function will convert a string into a...
|
by: Edward Diener |
last post by:
By reuse, I mean a function in an assembly which is called in another
assembly.
By a mixed-mode function I mean a function whose signature has one or
more CLR types and one or more non-CLR...
|
by: |
last post by:
All,
I have a MFC Mixed mode dll which is working well. I am now tring to use a
regular C++ class from another DLL which has a method called GetMessage.
When I link I get 2 error messages:
...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| | |