« Previous entry | Next entry » Browse > Snippets
Skip to comments (23)
javascript to php function calls
Posted by Erik on Jan 02 2006 @ 12:55 :: 7058 unique visits
With all the AJAX hype lately I created these simple javascript to php function call scripts.usage
in your javascript:
fn_call(name, return, arg1, arg2, ...);
name is the function name to call.
return is the function which should handle the return value.
arg* the arguments for the php function
fn_url should contain the php file which contains the function (default is the current url).
fn_debug can be set to true for debug messages.
in your php code all functions which start with fn_ are callable (see example below).
How does it work
The script just simply converts all javascript variables to a post sting which php automatically converts to the right php variables.
The return value of your php function is converted to a javascript variable which is passed to the return handler.
fn.inc.php
CODE: PHP
<?
// fn.inc.php v1.1 by Erik
function __fn_string($var) {
// because eval won't handle multiline string we have to convert the \n
$var = addslashes($var);
return str_replace("\n", '\n', $var);
}
// convert a php variable to a javascript variable
function __fn_tojs($name, $var) {
if (is_int($var)) {
echo $name.' = '.$var.';';
} else if (is_float($var)) {
echo $name.' = '.sprintf('%f', $var).';';
}
else if (is_bool($var)) {
if ($var) {
echo $name.' = true;';
} else {
echo $name.' = false;';
}
}
else if (is_array($var)) {
echo $name.' = new Array();';
foreach ($var as $i => $e) {
if (is_string($i)) {
$i = '"'.__fn_string($i).'"';
}
else if (is_bool($i)) {
if ($i) {
$i = 'true';
} else {
$i = 'false';
}
}
__fn_tojs($name.'['.$i.']', $e);
}
}
else if (is_string($var)) {
echo $name.' = "'.__fn_string($var).'";';
}
else if (is_null($var)) {
echo $name.' = null;';
}
else if (is_object($var)) {
echo $name.' = "'.__fn_string(serialize($var)).'";';
}
else {
// $r is a resource which can't be returend in any way
echo $name.' = "resource";';
}
}
function __fn_error($msg) {
die('/* '.$msg.' */ '); // comments to eval won't error
}
function __fn_handler() {
$func = 'fn_'.$_POST['fn'];
// check if the function is user defined
$ufuncs = get_defined_functions();
if (array_search($func, $ufuncs['user']) === false) {
__fn_error('unknown function');
}
// are we interrested in the return value?
$iret = isset($_POST['ret']) ? $_POST['ret'] : 0;
// unset these so only the arguments are left (easyer for the foreach)
unset($_POST['fn']);
unset($_POST['ret']);
// use an @ so we won't get any warnings about argument count mismatch
$r = @call_user_func_array($func, $_POST);
if ($iret) {
__fn_tojs('fn_ret', $r);
} else {
echo '/* not interrested */ ';
}
}
function fn_iscall() {
return isset($_POST['fn']);
}
if (fn_iscall()) {
register_shutdown_function('__fn_handler');
}
?>
// fn.inc.php v1.1 by Erik
function __fn_string($var) {
// because eval won't handle multiline string we have to convert the \n
$var = addslashes($var);
return str_replace("\n", '\n', $var);
}
// convert a php variable to a javascript variable
function __fn_tojs($name, $var) {
if (is_int($var)) {
echo $name.' = '.$var.';';
} else if (is_float($var)) {
echo $name.' = '.sprintf('%f', $var).';';
}
else if (is_bool($var)) {
if ($var) {
echo $name.' = true;';
} else {
echo $name.' = false;';
}
}
else if (is_array($var)) {
echo $name.' = new Array();';
foreach ($var as $i => $e) {
if (is_string($i)) {
$i = '"'.__fn_string($i).'"';
}
else if (is_bool($i)) {
if ($i) {
$i = 'true';
} else {
$i = 'false';
}
}
__fn_tojs($name.'['.$i.']', $e);
}
}
else if (is_string($var)) {
echo $name.' = "'.__fn_string($var).'";';
}
else if (is_null($var)) {
echo $name.' = null;';
}
else if (is_object($var)) {
echo $name.' = "'.__fn_string(serialize($var)).'";';
}
else {
// $r is a resource which can't be returend in any way
echo $name.' = "resource";';
}
}
function __fn_error($msg) {
die('/* '.$msg.' */ '); // comments to eval won't error
}
function __fn_handler() {
$func = 'fn_'.$_POST['fn'];
// check if the function is user defined
$ufuncs = get_defined_functions();
if (array_search($func, $ufuncs['user']) === false) {
__fn_error('unknown function');
}
// are we interrested in the return value?
$iret = isset($_POST['ret']) ? $_POST['ret'] : 0;
// unset these so only the arguments are left (easyer for the foreach)
unset($_POST['fn']);
unset($_POST['ret']);
// use an @ so we won't get any warnings about argument count mismatch
$r = @call_user_func_array($func, $_POST);
if ($iret) {
__fn_tojs('fn_ret', $r);
} else {
echo '/* not interrested */ ';
}
}
function fn_iscall() {
return isset($_POST['fn']);
}
if (fn_iscall()) {
register_shutdown_function('__fn_handler');
}
?>
fn.js
CODE: JAVASCRIPT
// fn.js v1.0 by Erik
var fn_debug = false;
var fn_url = document.location.href;
function __fn_req() {
// http://www.codepost.org/browse/snippets/59
var types = [
'Microsoft.XMLHTTP',
'MSXML2.XMLHTTP.5.0',
'MSXML2.XMLHTTP.4.0',
'MSXML2.XMLHTTP.3.0',
'MSXML2.XMLHTTP'
];
for (var i = 0; i < types.length; i++) {
try {
return new ActiveXObject(types[i]);
} catch(e) {}
}
try {
return new XMLHttpRequest();
} catch(e) {}
return false; // XMLHttpRequest not supported
}
// convert a javascript variable to a php post argument
function __fn_topost(n, v) {
var t = typeof v;
if (t == 'number') {
return '&'+n+'='+v;
}
else if (t == 'boolean') {
if (v) {
return '&'+n+'=1';
} else {
return '&'+n+'=0';
}
}
else if (t == 'object') {
if (v == null) { // null seems to be an object
return '&'+n+'=null';
} else if (v.constructor == Array) {
var ret = '';
var len = v.length;
for (var i = 0; i < len; i++) {
if (v[i] == null) { // __fn_topost(v[i]) will cause a warning
ret += '&'+n+'['+i+']=null';
} else {
ret += __fn_topost(n+'['+i+']', v[i]);
}
}
return ret;
} else {
return '&'+n+'='+escape(v.toString());
}
}
/* this is not needed as the else case does teh same
else if (t == 'function') {
return '&'+n+'='+escape(v.toString());
}*/
else {
return '&'+n+'='+escape(v);
}
}
function __fn_call(debug, args) {
var req = __fn_req();
if (typeof req == 'boolean') {
if (debug) {
alert('--fn-debug--\nXMLHttpRequest not supported');
}
} else {
var post = 'fn='+args[0];
var wret = 0;
if ((typeof args[1] == 'function') ||
(typeof args[1] == 'string')) {
wret = 1; // we are interrested in the return value
} else if (debug) {
wret = 1;
}
post += '&ret=' + wret;
// construct all the arguments
var alen = args.length;
for (var i = 2; i < alen; i++) {
post += __fn_topost(i-2, args[i]);
}
// need to do something with the return value?
if (wret) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
if (debug) {
var prnt = req.responseText;
prnt = prnt.replace(/;/g, ';\n');
prnt = prnt.replace(/\\n/g, '\n');
alert('--fn-debug--responseText--\n'+prnt);
}
var fn_ret = false;
try {
eval(req.responseText);
} catch(e) { }
if (typeof args[1] == 'function') {
args[1](fn_ret);
} else if (typeof args[1] == 'string') {
eval(args[1]);
}
} else {
if (debug) {
alert('--fn-debug--statusText--\n'+req.statusText);
}
}
}
};
}
if (debug) {
alert('--fn-debug--post--\n'+post.replace(/&/g, '\n&'));
}
req.open('POST', fn_url, true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(post);
}
}
function fn_call() {
__fn_call(fn_debug, arguments);
}
function fn_call_debug() {
__fn_call(true, arguments);
}
var fn_debug = false;
var fn_url = document.location.href;
function __fn_req() {
// http://www.codepost.org/browse/snippets/59
var types = [
'Microsoft.XMLHTTP',
'MSXML2.XMLHTTP.5.0',
'MSXML2.XMLHTTP.4.0',
'MSXML2.XMLHTTP.3.0',
'MSXML2.XMLHTTP'
];
for (var i = 0; i < types.length; i++) {
try {
return new ActiveXObject(types[i]);
} catch(e) {}
}
try {
return new XMLHttpRequest();
} catch(e) {}
return false; // XMLHttpRequest not supported
}
// convert a javascript variable to a php post argument
function __fn_topost(n, v) {
var t = typeof v;
if (t == 'number') {
return '&'+n+'='+v;
}
else if (t == 'boolean') {
if (v) {
return '&'+n+'=1';
} else {
return '&'+n+'=0';
}
}
else if (t == 'object') {
if (v == null) { // null seems to be an object
return '&'+n+'=null';
} else if (v.constructor == Array) {
var ret = '';
var len = v.length;
for (var i = 0; i < len; i++) {
if (v[i] == null) { // __fn_topost(v[i]) will cause a warning
ret += '&'+n+'['+i+']=null';
} else {
ret += __fn_topost(n+'['+i+']', v[i]);
}
}
return ret;
} else {
return '&'+n+'='+escape(v.toString());
}
}
/* this is not needed as the else case does teh same
else if (t == 'function') {
return '&'+n+'='+escape(v.toString());
}*/
else {
return '&'+n+'='+escape(v);
}
}
function __fn_call(debug, args) {
var req = __fn_req();
if (typeof req == 'boolean') {
if (debug) {
alert('--fn-debug--\nXMLHttpRequest not supported');
}
} else {
var post = 'fn='+args[0];
var wret = 0;
if ((typeof args[1] == 'function') ||
(typeof args[1] == 'string')) {
wret = 1; // we are interrested in the return value
} else if (debug) {
wret = 1;
}
post += '&ret=' + wret;
// construct all the arguments
var alen = args.length;
for (var i = 2; i < alen; i++) {
post += __fn_topost(i-2, args[i]);
}
// need to do something with the return value?
if (wret) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
if (debug) {
var prnt = req.responseText;
prnt = prnt.replace(/;/g, ';\n');
prnt = prnt.replace(/\\n/g, '\n');
alert('--fn-debug--responseText--\n'+prnt);
}
var fn_ret = false;
try {
eval(req.responseText);
} catch(e) { }
if (typeof args[1] == 'function') {
args[1](fn_ret);
} else if (typeof args[1] == 'string') {
eval(args[1]);
}
} else {
if (debug) {
alert('--fn-debug--statusText--\n'+req.statusText);
}
}
}
};
}
if (debug) {
alert('--fn-debug--post--\n'+post.replace(/&/g, '\n&'));
}
req.open('POST', fn_url, true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(post);
}
}
function fn_call() {
__fn_call(fn_debug, arguments);
}
function fn_call_debug() {
__fn_call(true, arguments);
}
Example usage
example.php
CODE: PHP
include './fn.inc.php';
function fn_hello($name) {
return "hello $name";
}
function fn_hello($name) {
return "hello $name";
}
somewhere in your javascript
CODE: JAVASCRIPT
fn_url = 'example.php'; // only needs to be set once somewhere
...
function theresult(str) {
alert(str);
}
fn_call('hello', theresult, 'erik');
...
function theresult(str) {
alert(str);
}
fn_call('hello', theresult, 'erik');
23 comments posted so far
Add your own »
2. On Jan 19 2006 @ 12:01 Erik wrote:
Added a try-catch block around the eval() of the responseText to ignore PHP errors.CODE: JAVASCRIPT
var fn_ret = false;
try {
eval(req.responseText);
} catch(e) { }
try {
eval(req.responseText);
} catch(e) { }
To find these errors set fn_debug = true; and you will see the responseText.
3. On Mar 09 2006 @ 14:59 guest wrote:
Why in the name of good god, the script (javascript) return false even if I don´t have a return FALSE in PHP function???4. On Mar 09 2006 @ 17:55 Erik wrote:
Show us your code so we can see.5. On Jul 09 2006 @ 04:24 guest wrote:
thats bullshit man6. On Aug 17 2006 @ 16:44 guest wrote:
i want to call function whenever we click on combo button..7. On Sep 15 2006 @ 21:41 guest wrote:
msxml6.0 was released. Add this to your code 'MSXML2.XMLHTTP.6.0'.Why do you care to do that? bceause msxml6.0 will deprecate msxml4.0 sooner or later. Also msxml5.0 should not be used, since it is not a publically released version.
-
8. On Mar 02 2009 @ 07:48 guest wrote:
When the wolf wow gold finally found the hole Buy Wow Gold in the chimney he Cheap WoW Gold crawled down and KERSPLASH right into that kettle of water cheapest wow gold and that was the end of his troubles with the big bad wolf.The next day the wow gold cheap little pig invited his mother over . She said "You see it is just as I told you. The way to get along in the world is to do things as well as you can." Fortunately for that world of warcraft gold little pig, he learned that lesson. And he just lived happily ever after! buy wow gold .
9. On Mar 03 2009 @ 10:38 Certification wrote:
msxml6.0 was released. Add this to your code 'MSXML2.XMLHTTP.6.0 you must add this in your function and i must say that your work is awesome and i would try this just after my 70-528 Microsoft .NET Framework 2.0 - Web-based client development certification exam about which I'm confident to pass in first attempt as i have pass my 70-647 for Windows Server 2008, Enterprise Administrator certifications exam in first attempt along with 70-271 exam for Troubleshoot Microsoft Windows XP with proper guidance and one other thing i must say that your work is really appreciating and your deep search on your work is awesome.10. On Mar 18 2009 @ 09:44 guess wrote:
Weaknesses of world of warcraft gold the client-server model used by World of Warcraft have been wow power levelingexploited in order to crash the cluster of servers that wow8goldmake up a realm. Exploits also include characters being able to instantly Cheapest Wow Goldchange location or teleport. The situation became worse when cheap wow goldtrying to coordinate activities across a number of players or guilds on the same realm.World of Warcraft Lead Producer, stated that new realms would be introduced to relieve warhammer gold the burden on existing ones. Existing realms would be upgraded.Although the game wow gold follows a similar model to others in the genreand was noted for having wow gold cheap many familiar concepts from roleplaying games, the new approaches gold4powerto reduce pauses between game encounters was well liked. At various times, World of Warcraft players have experienced problems with connecting to and logging in to wow gold for salethe game. Sudden server crashes that would force realms offline also occurred.
11. On Apr 15 2009 @ 04:34 guest wrote:
exam afterwow goldhis rescuewow goldat 7:19 p.m.wow goldthe Navy wow goldCentral Command wow gold]wow goldsaid.12. On Apr 15 2009 @ 04:35 guest wrote:
"The captaindofus kamasis in kamas dofusgood health.dofus kamasHe's showeredkamas dofusup and inacheter dofusa cleanbuy kamasset of acheter kamasclothesdofus kamaskamas dofus13. On Apr 15 2009 @ 04:35 guest wrote:
Gortney said world of warcraft goldin a cheap wow goldtelephone news wow orconference wow power levelingfrom Navy world of warcraft gold\Central Commandwow poin Bahrain.wow orU.S.buy wow goldforces cheap wow goldmoved to wow power levelingrescue Phillipswow powerlevelingafter seeing dofus kamas him inkamas dofus\imminentLord of the Rings Online Golddanger onLOTRO Goldthe lifeboat, LOTR GoldGortney said.flyff moneyA fourthflyff penyapirate was buy flyff goldnegotiating ffxi gilPhillips' fatebuy ffxi gilaboard theFinal Fantasy XI gilnearby buy Warhammer goldUSS Bainbridge.Warhammer gold"While workingEverQuest 2 goldthrough theeq2 platnegotiationsNew Orleans EverQuest plateq platEverQuest goldled 80-72 heading into the final quarter.Hornets center Tyson Chandlereq2 plateverquest 2 goldflyff penyabuy flyff gold missed his second consecutive game because of a stiff neck. He was replaced by flyff moneyeve iskeve online iskHilton Armstrong.Notes: Toronto guard Anthony Parker, who missed twoworld of warcraft goldbuy wow goldcheap wow gold games with a sprained ankle, world of warcraft goldwow gold kaufencheap wow goldreturned to the lineup wow powow orbuy wow goldbut didn't start for chaeap wow goldbuy wow goldcheap wow goldthe first time in 176 ffxi gilfinal fantasy xi gilbuy ffxi gilcareer games with maple story mesosmaplestory mesosrunescape goldthe Raptors. ... Posey made a career-high seven 3-pointers against Washington on Dec. 15, 2006. ...runescape moneyaoc goldage of conan gold Posey was called for runescape moneyaoc goldage of conan golda technical foul in the final minute of the first half. ... Toronto signed free-agent center Jake Voskuhl.14. On Apr 15 2009 @ 04:35 guest wrote:
process tonight,wow goldthe on-scenewow goldcommander from wow goldthe Bainbridgewow goldmade thewow golddecision that wow goldthe captain's15. On Apr 15 2009 @ 04:36 guest wrote:
life was dofus kamasin immediate kamas dofusdanger, and acheter kamasthe threedofus kamas pirates werekamas dofuskilled," Gortney acheter kamassaid. "The dofus kamaspirate whokamas dofussurrendered buy kamasearlier todaydofus kamasis beingkamas dofustreated humanely;achat kamashis counterpartsdofus kamaswho continued kamas dofusto fight paidacheter des kamas with their lives.16. On May 05 2009 @ 16:24 guest wrote:
Bon marche de <a href="http://www.servicegamer.com/dofus-kamas-fr.asp">Dofus Kamas</a>.achat de <a href="http://www.mmovs.com/dofus-kamas-fr/">Dofus</a> Kamas.le prix moins cher.nous vendons <a href="http://www.mmovs.com/wakfu-kamas-fr/">Wakfu</a> kamas ,or de dofus.24/7 appui-en-ligne et livraison rapide.<a href="http://www.servicegamer.com/wakfu-kamas.asp">Wakfu Kamas</a>Gift: <a href="http://www.shopcreativegift.com/">shopcreativegift</a>
china: <a href="http://chinaserving.com/">chinaserving</a>
17. On May 05 2009 @ 16:24 guest wrote:
Bon marche de dofus kamas.achat de Dofus.le prix moins cher.nous vendons Wakfu kamas ,or de dofus.24/7 appui-en-ligne et livraison rapide.Wakfu Kamasshopcreativegift
chinaserving
18. On May 18 2009 @ 02:56 DONG wrote:
It is a very nice game <a href="http://www.virgame.com/silkroad-online-c-64.html"> silkroad gold</a>, I like <a href="http://www.virgame.com/silkroad-online-c-64.html"> sro gold</a>. You can play it <a href="http://www.virgame.com/ silkroad-online-c-64.html">silkroad online gold</a>, you can buy the cheap <a href="http://www.virgame.com/ silkroad-online-c-64.html"> silk road gold</a>. You smart and buy <a href="http://www.virgame.com/ silkroad-online-c-64.html"> cheap silkroad gold</a>.19. On May 18 2009 @ 02:57 dong wrote:
Do you know seal cegel ? I like it.My brother often go to the internet bar to buy sealonline cegel and play it.After school, He likes playing games using these seal online cegel with his friend.One day, he give me many cheap seal cegel and play the game with me.I came to the bar and found buy seal online cegel was so cheap. So, I also go to play game with him.
20. On May 18 2009 @ 02:58 dong wrote:
If you want to buy gold, you can Tibia Gold , because the game nice Tibia coins . Thanks for you buy Tibia money , you will find tibia gp , You are right Tibia Platinum ,I am glad to see you.21. On May 18 2009 @ 02:58 dong wrote:
It is a very nice game silkroad gold, I like sro gold. You can play it silkroad online gold, you can buy the cheap silk road gold. You smart and buy cheap silkroad gold.22. On Jun 06 2009 @ 08:59 guest wrote:
<a href="http://www.topowerleveling.com">world of warcraft power leveling</a> <a href="http://www.topowerleveling.com">wow power leveling</a> <a href="http://www.topowerleveling.com">power leveling</a> <a href="http://www.gowowpowerleveling.com">wow gold</a> <a href="http://www.cnaosheng.com.cn">橡塑发泡</a> <a href="http://www.ac021.com">直流电源</a> <a href="http://www.paper-cup-machine.com">paper cup machine</a> <a href="http://www.liandaauto.com/main.asp">Mass air flow</a> <a href="http://www.pabx365.com">程控交换机</a> <a href="http://www.mystery.net.cn/index/index.php">餐饮软件</a> <a href="http://www.mystery.net.cn">餐饮软件</a> <a href="http://www.mystery.net.cn">收银机</a> <a href="http://www.zhongke-china.com/product.asp">automatic rigid box line</a> <a href="http://www.zhongke-china.com/product.asp">paper converting and wrapping machines</a> <a href="http://www.zhongke-china.com/product.asp">automatic box makers</a> <a href="http://www.zhongke-china.com/about.asp">rigid set-up gift box</a>,<a href="http://www.zhongke-china.com/about.asp">paperboard converting equipment</a><a href="http://www.lszwjx.com">气动马达</a> <a href="http://www.lszwjx.com">气动搅拌机</a> <a href="http://www.lszwjx.com">防爆马达</a> <a href="http://www.lszwjx.com/about.htm">防爆搅拌机</a> <a href="http://www.lszwjx.com/about.htm">气动搅拌机</a> <a href="http://www.lszwjx.com/news.htm">空气马达</a> <a href="http://www.lszwjx.com/news.htm">防爆马达</a> <a href="http://www.lszwjx.com/product.htm">气动马达</a> <a href="http://www.lszwjx.com/product2.htm">油漆搅拌机</a> <a href="http://www.lszwjx.com/plist493.htm">油漆搅拌器</a> <a href="http://www.lszwjx.com/product2.htm">气动搅拌器</a> <a href="http://www.lszwjx.com/plist490.htm">防爆搅拌器</a> <a href="http://www.lszwjx.com/product2.htm">油墨搅拌器</a> <a href="http://www.lszwjx.com/plist495.htm">油墨搅拌机</a> <a href="http://www.ruian2machine.cn">安检门</a> <a href="http://www.ruian2machine.cn">金属探测器</a> <a href="http://www.ruian2machine.cn">金属探测仪</a> <a href="http://www.plastic-thermoforming-machine.com/product.htm">thermoforming Equipment</a> <a href="http://www.packagemachinery.cn">bag making machine</a> <a href="http://www.todesign.com.cn">工业设计</a> <a href="http://www.todesign.com.cn">产品设计</a> <a href="http://www.tzonegroup.cn">储罐</a> <a href="http://www.tzonegroup.cn/about.asp">中药提取设备</a> <a href="http://www.tzonegroup.cn/products.asp">乳化机</a> <a href="http://www.rajayj.cn">反应釜</a> <a href="http://www.rajayj.cn">真空干燥箱</a> <a href="http://www.ashuashi.com.cn">厚壁钢管</a>
<a href="http://www.gowowpowerleveling.com">power leveling</a> <a href="http://www.gowowpowerleveling.com">wow power leveling</a> <a href="http://www.zhongke-china.com">paper box</a> <a href="http://www.zhongke-china.com/about.asp">paper box equipment</a> <a href="http://www.plastic-thermoforming-machine.com">thermoforming Equipment</a> <a href="http://www.plastic-thermoforming-machine.com">Plastic Machinery</a> <a href="http://www.plastic-thermoforming-machine.com/about.htm">Plastic Machine</a> <a href="http://www.wzbtjx.cn">马达</a> <a href="http://www.wzbtjx.cn">气动马达</a> <a href="http://www.wzbtjx.cn">搅拌机</a>
23. On Jun 25 2009 @ 04:16 guest wrote:
DVD Audio RipperFree DVD Audio Ripper
DVD Audio Ripper for Mac
DVD to MP4 Converter
DVD to MP4 Converter for Mac
DVD to iPod Converter
free DVD to iPod Converter
DVD to iPod Converter for Mac
DVD Ripper
Diablo 2 CD Key
Diablo 2 CD Keys
Free DVD Ripper
DVD Ripper for Mac
NFL Jerseys
Scoccer Jerseys
Hockey Jerseys
MLB Jerseys
NHL Jerseys
Nike Sneakers
1. On Jan 10 2006 @ 10:03 Erik wrote:
As noted by Niek the following code would change the floating point number 1.0 into an integer 1echo $name.' = '.$var.';';
}
So I changed it to:
echo $name.' = '.$var.';';
} else if (is_float($var)) {
echo $name.' = '.sprintf('%f', $var).';';
}