FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to convert this PHP into JavaScript
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
How to convert this PHP into JavaScript [message #173146] Thu, 24 March 2011 14:23 Go to next message
Oltmans is currently offline  Oltmans
Messages: 1
Registered: March 2011
Karma: 0
Junior Member
Hi PHP gurus, I hope you're doing well.

I'm trying to convert a PHP script into JavaScript. I'm posting here
because I don't know much PHP and I hope someone among you can help.
Here is the PHP

array(
'abc' => '1 AND (2 OR
3)', // Define how to
use the following criteria
'def' => array('marketing_campaign_id', 'status',
'status'), // Filter by these three criteria
'ghi' => array('eq', 'eq',
'eq')
);


I need to convert above into JavaScript object which looks like

{

'abc' : '1 AND (2 OR 3)'
}


but I don't know how to convert

array('marketing_campaign_id', 'status', 'status')

into equivalent JavaScript. Can someone please let me know how to
convert above into JavaScript? I will really appreciate your help in
this regard. Thanks!
Re: How to convert this PHP into JavaScript [message #173147 is a reply to message #173146] Thu, 24 March 2011 15:03 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 24/03/2011 15:23, Oltmans escribió/wrote:
> Hi PHP gurus, I hope you're doing well.
>
> I'm trying to convert a PHP script into JavaScript. I'm posting here
> because I don't know much PHP and I hope someone among you can help.
> Here is the PHP
>
> array(
> 'abc' => '1 AND (2 OR
> 3)', // Define how to
> use the following criteria
> 'def' => array('marketing_campaign_id', 'status',
> 'status'), // Filter by these three criteria
> 'ghi' => array('eq', 'eq',
> 'eq')
> );
>
>
> I need to convert above into JavaScript object which looks like
>
> {
>
> 'abc' : '1 AND (2 OR 3)'
> }
>
>
> but I don't know how to convert
>
> array('marketing_campaign_id', 'status', 'status')
>
> into equivalent JavaScript. Can someone please let me know how to
> convert above into JavaScript? I will really appreciate your help in
> this regard. Thanks!

http://php.net/json_encode should do the trick


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: How to convert this PHP into JavaScript [message #173148 is a reply to message #173146] Thu, 24 March 2011 16:50 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/24/2011 10:23 AM, Oltmans wrote:
> Hi PHP gurus, I hope you're doing well.
>
> I'm trying to convert a PHP script into JavaScript. I'm posting here
> because I don't know much PHP and I hope someone among you can help.
> Here is the PHP
>
> array(
> 'abc' => '1 AND (2 OR
> 3)', // Define how to
> use the following criteria
> 'def' => array('marketing_campaign_id', 'status',
> 'status'), // Filter by these three criteria
> 'ghi' => array('eq', 'eq',
> 'eq')
> );
>
>
> I need to convert above into JavaScript object which looks like
>
> {
>
> 'abc' : '1 AND (2 OR 3)'
> }
>
>
> but I don't know how to convert
>
> array('marketing_campaign_id', 'status', 'status')
>
> into equivalent JavaScript. Can someone please let me know how to
> convert above into JavaScript? I will really appreciate your help in
> this regard. Thanks!

If you want to write javascript, you should ask in a javascript newsgroup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to convert this PHP into JavaScript [message #173151 is a reply to message #173146] Thu, 24 March 2011 18:05 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Thu, 24 Mar 2011 07:23:56 -0700, Oltmans wrote:

> Hi PHP gurus, I hope you're doing well.
>
> I'm trying to convert a PHP script into JavaScript. I'm posting here
> because I don't know much PHP and I hope someone among you can help.
> Here is the PHP
>
> array(
> 'abc' => '1 AND (2 OR
> 3)', // Define how to use
> the following criteria
> 'def' => array('marketing_campaign_id', 'status',
> 'status'), // Filter by these three criteria
> 'ghi' => array('eq', 'eq',
> 'eq')
> );
>
>
> I need to convert above into JavaScript object which looks like
>
> {
>
> 'abc' : '1 AND (2 OR 3)'
> }
>
>
> but I don't know how to convert
>
> array('marketing_campaign_id', 'status', 'status')
>
> into equivalent JavaScript. Can someone please let me know how to
> convert above into JavaScript? I will really appreciate your help in
> this regard. Thanks!

Here is a display of some PHP source code that generates a document which
contains some javascript, and passes an object to that javascript using
JSON.

http://www.sined.co.uk/tmp/oltmans.htm

And here is the output it generates:

http://www.sined.co.uk/tmp/oltmans.php

Looking at these will probably confuse you, but might instead be of some
help.

Rgds

Denis McMahon
Re: How to convert this PHP into JavaScript [message #173167 is a reply to message #173148] Fri, 25 March 2011 18:59 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 3/24/2011 12:50 PM, Jerry Stuckle wrote:
> On 3/24/2011 10:23 AM, Oltmans wrote:
>> Hi PHP gurus, I hope you're doing well.
>>
>> I'm trying to convert a PHP script into JavaScript. I'm posting here
>> because I don't know much PHP and I hope someone among you can help.
>> Here is the PHP
>>
>> array(
>> 'abc' => '1 AND (2 OR
>> 3)', // Define how to
>> use the following criteria
>> 'def' => array('marketing_campaign_id', 'status',
>> 'status'), // Filter by these three criteria
>> 'ghi' => array('eq', 'eq',
>> 'eq')
>> );
>>
>>
>> I need to convert above into JavaScript object which looks like
>>
>> {
>>
>> 'abc' : '1 AND (2 OR 3)'
>> }
>>
>>
>> but I don't know how to convert
>>
>> array('marketing_campaign_id', 'status', 'status')
>>
>> into equivalent JavaScript. Can someone please let me know how to
>> convert above into JavaScript? I will really appreciate your help in
>> this regard. Thanks!
>
> If you want to write javascript, you should ask in a javascript newsgroup.
>

No Jerry, not this time. He has a PHP array and he wants to use that
PHP array to generate a script in javascript. That means that knowledge
of BOTH is required.

This is more properly asked here in this PHP group than in the
Javascript group. Everyone here also knows at least SOME Javascript.
The reverse is not true for the Javascript group. People there may not
know ANY PHP (though most seem to).

--
Shelly
Re: How to convert this PHP into JavaScript [message #173168 is a reply to message #173167] Fri, 25 March 2011 19:22 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/25/2011 2:59 PM, sheldonlg wrote:
> On 3/24/2011 12:50 PM, Jerry Stuckle wrote:
>> On 3/24/2011 10:23 AM, Oltmans wrote:
>>> Hi PHP gurus, I hope you're doing well.
>>>
>>> I'm trying to convert a PHP script into JavaScript. I'm posting here
>>> because I don't know much PHP and I hope someone among you can help.
>>> Here is the PHP
>>>
>>> array(
>>> 'abc' => '1 AND (2 OR
>>> 3)', // Define how to
>>> use the following criteria
>>> 'def' => array('marketing_campaign_id', 'status',
>>> 'status'), // Filter by these three criteria
>>> 'ghi' => array('eq', 'eq',
>>> 'eq')
>>> );
>>>
>>>
>>> I need to convert above into JavaScript object which looks like
>>>
>>> {
>>>
>>> 'abc' : '1 AND (2 OR 3)'
>>> }
>>>
>>>
>>> but I don't know how to convert
>>>
>>> array('marketing_campaign_id', 'status', 'status')
>>>
>>> into equivalent JavaScript. Can someone please let me know how to
>>> convert above into JavaScript? I will really appreciate your help in
>>> this regard. Thanks!
>>
>> If you want to write javascript, you should ask in a javascript
>> newsgroup.
>>
>
> No Jerry, not this time. He has a PHP array and he wants to use that PHP
> array to generate a script in javascript. That means that knowledge of
> BOTH is required.
>
> This is more properly asked here in this PHP group than in the
> Javascript group. Everyone here also knows at least SOME Javascript. The
> reverse is not true for the Javascript group. People there may not know
> ANY PHP (though most seem to).
>

No, Sheldon, he needs to be in comp.lang.javascript - where some of the
people there know PHP.

The first thing he needs is the appropriate javascript he needs - i.e.
hand coding it. The generating the appropriate javascript from the
array is simple.

Now, if he would have said "I have this javascript I need to generate
from this PHP array...", I would agree this is more appropriate.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to convert this PHP into JavaScript [message #173169 is a reply to message #173168] Fri, 25 March 2011 20:51 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Fri, 25 Mar 2011 15:22:42 -0400, Jerry Stuckle wrote:

> On 3/25/2011 2:59 PM, sheldonlg wrote:
>> On 3/24/2011 12:50 PM, Jerry Stuckle wrote:
>>> On 3/24/2011 10:23 AM, Oltmans wrote:
>>>> Hi PHP gurus, I hope you're doing well.
>>>>
>>>> I'm trying to convert a PHP script into JavaScript. I'm posting here
>>>> because I don't know much PHP and I hope someone among you can help.
>>>> Here is the PHP
>>>>
>>>> array(
>>>> 'abc' => '1 AND (2 OR
>>>> 3)', // Define how to
>>>> use the following criteria
>>>> 'def' => array('marketing_campaign_id', 'status', 'status'), //
>>>> Filter by these three criteria 'ghi' => array('eq', 'eq',
>>>> 'eq')
>>>> );
>>>>
>>>>
>>>> I need to convert above into JavaScript object which looks like
>>>>
>>>> {
>>>>
>>>> 'abc' : '1 AND (2 OR 3)'
>>>> }
>>>>
>>>>
>>>> but I don't know how to convert
>>>>
>>>> array('marketing_campaign_id', 'status', 'status')
>>>>
>>>> into equivalent JavaScript. Can someone please let me know how to
>>>> convert above into JavaScript? I will really appreciate your help in
>>>> this regard. Thanks!
>>>
>>> If you want to write javascript, you should ask in a javascript
>>> newsgroup.
>>>
>>>
>> No Jerry, not this time. He has a PHP array and he wants to use that
>> PHP array to generate a script in javascript. That means that knowledge
>> of BOTH is required.
>>
>> This is more properly asked here in this PHP group than in the
>> Javascript group. Everyone here also knows at least SOME Javascript.
>> The reverse is not true for the Javascript group. People there may not
>> know ANY PHP (though most seem to).
>>
>>
> No, Sheldon, he needs to be in comp.lang.javascript - where some of the
> people there know PHP.
>
> The first thing he needs is the appropriate javascript he needs - i.e.
> hand coding it. The generating the appropriate javascript from the
> array is simple.
>
> Now, if he would have said "I have this javascript I need to generate
> from this PHP array...", I would agree this is more appropriate.

It does depend on your viewpoint of what he's asking.

My viewpoint is that he has a server side php application that generates
a (two dimensional associative) array in php, and that he subsequently
wants to use the data in that array client side with javascript running
in a website viewers browser.

So, I see his problem as being "how do I pass the information contained
in this (two dimensional associative) array in my php script on the
server into the webpage that I am generating to send to the website
viewers client browser so that it can be used by scripts running in a
client side context on that web page?"

My solution is to create a JSON string representation of his (two
dimensional associative) array, and put that string into the heredoc
output in a way that the javascript will create a javascript object that,
whilst not technically a (two dimensional associative) array, is similar
enough to one in structure that he can access the data elements of it in
a manner that correlates to the keys in the original php (two dimensional
associative) array.

Doubtless there are other solutions, if his array always had the same
structure and format, he could write code to generate whatever javascript
representation of the array he wished[1], but the json approach means
that if the structure of his php generated array changes, the transfer of
that array into a javascript object is probably robust enough to not need
"tweaking", and the only changes he's likely to have to make to his
javascript will be how he uses the modified object, without having to
worry about restructuring the conversion from the php array to the
javascript object.

Rgds

Denis McMahon

[1] eg:
<?php
// write the php array '$data' to a js object 'phpData'
echo <<<EOJS
<script type="text/javascript">
var phpData;
phpData.abc = "{$data['abc']}";
phpData.def = ["{$data['def'][0]}", "{$data['def'][1]}",
"{$data['def'][2]}"];
phpData.ghi = ["{$data['ghi'][0]}", "{$data['ghi'][1]}",
"{$data['ghi'][2]}"];
</script>
EOJS;
?>
but this method has at least 2 limitations. It is tied to the given
structure of the $data array, and if any of the string values contains a
double quote character, the resulting javascript will be broken.
Re: How to convert this PHP into JavaScript [message #173170 is a reply to message #173151] Fri, 25 March 2011 20:56 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Denis McMahon wrote:

> Oltmans wrote:
>> […] Here is the PHP
>>
>> array(
>> 'abc' => '1 AND (2 OR
>> 3)', // Define how to use
>> the following criteria
>> 'def' => array('marketing_campaign_id', 'status',
>> 'status'), // Filter by these three criteria
>> 'ghi' => array('eq', 'eq',
>> 'eq')
>> );
>>
>>
>> I need to convert above into JavaScript object which looks like
>>
>> {
>>
>> 'abc' : '1 AND (2 OR 3)'
>> }
>>
>> […]
>
> Here is a display of some PHP source code that generates a document which
> contains some javascript, and passes an object to that javascript using
> JSON.
>
> http://www.sined.co.uk/tmp/oltmans.htm
>
> And here is the output it generates:
>
> http://www.sined.co.uk/tmp/oltmans.php
>
> Looking at these will probably confuse you, but might instead be of some
> help.

Version information from the OP being missing, the correct answer is of
course to use PHP's json_encode() function¹ to generate JSON (JavaScript
Object Notation)² from the PHP value, which is compatible with all
statistically significant client-side ECMAScript implementations³ (every
syntactically valid JSON object string is a syntactically valid ECMAScript
Object initializer/literal, and every syntactically valid JSON array string
is a syntactically valid Array initializer/literal; the reverse is not
true):

<?php echo json_encode(array('abc' => '1 AND (2 OR 3)')); ?>

______
¹ <http://php.net/json_encode>
² <http://json.org/>
³ <http://PointedEars.de/scripts/test/es-matrix/#!>


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
Re: How to convert this PHP into JavaScript [message #173171 is a reply to message #173169] Fri, 25 March 2011 21:01 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/25/2011 4:51 PM, Denis McMahon wrote:
> On Fri, 25 Mar 2011 15:22:42 -0400, Jerry Stuckle wrote:
>
>> On 3/25/2011 2:59 PM, sheldonlg wrote:
>>> On 3/24/2011 12:50 PM, Jerry Stuckle wrote:
>>>> On 3/24/2011 10:23 AM, Oltmans wrote:
>>>> > Hi PHP gurus, I hope you're doing well.
>>>> >
>>>> > I'm trying to convert a PHP script into JavaScript. I'm posting here
>>>> > because I don't know much PHP and I hope someone among you can help.
>>>> > Here is the PHP
>>>> >
>>>> > array(
>>>> > 'abc' => '1 AND (2 OR
>>>> > 3)', // Define how to
>>>> > use the following criteria
>>>> > 'def' => array('marketing_campaign_id', 'status', 'status'), //
>>>> > Filter by these three criteria 'ghi' => array('eq', 'eq',
>>>> > 'eq')
>>>> > );
>>>> >
>>>> >
>>>> > I need to convert above into JavaScript object which looks like
>>>> >
>>>> > {
>>>> >
>>>> > 'abc' : '1 AND (2 OR 3)'
>>>> > }
>>>> >
>>>> >
>>>> > but I don't know how to convert
>>>> >
>>>> > array('marketing_campaign_id', 'status', 'status')
>>>> >
>>>> > into equivalent JavaScript. Can someone please let me know how to
>>>> > convert above into JavaScript? I will really appreciate your help in
>>>> > this regard. Thanks!
>>>>
>>>> If you want to write javascript, you should ask in a javascript
>>>> newsgroup.
>>>>
>>>>
>>> No Jerry, not this time. He has a PHP array and he wants to use that
>>> PHP array to generate a script in javascript. That means that knowledge
>>> of BOTH is required.
>>>
>>> This is more properly asked here in this PHP group than in the
>>> Javascript group. Everyone here also knows at least SOME Javascript.
>>> The reverse is not true for the Javascript group. People there may not
>>> know ANY PHP (though most seem to).
>>>
>>>
>> No, Sheldon, he needs to be in comp.lang.javascript - where some of the
>> people there know PHP.
>>
>> The first thing he needs is the appropriate javascript he needs - i.e.
>> hand coding it. The generating the appropriate javascript from the
>> array is simple.
>>
>> Now, if he would have said "I have this javascript I need to generate
>> from this PHP array...", I would agree this is more appropriate.
>
> It does depend on your viewpoint of what he's asking.
>
> My viewpoint is that he has a server side php application that generates
> a (two dimensional associative) array in php, and that he subsequently
> wants to use the data in that array client side with javascript running
> in a website viewers browser.
>
> So, I see his problem as being "how do I pass the information contained
> in this (two dimensional associative) array in my php script on the
> server into the webpage that I am generating to send to the website
> viewers client browser so that it can be used by scripts running in a
> client side context on that web page?"
>
> My solution is to create a JSON string representation of his (two
> dimensional associative) array, and put that string into the heredoc
> output in a way that the javascript will create a javascript object that,
> whilst not technically a (two dimensional associative) array, is similar
> enough to one in structure that he can access the data elements of it in
> a manner that correlates to the keys in the original php (two dimensional
> associative) array.
>
> Doubtless there are other solutions, if his array always had the same
> structure and format, he could write code to generate whatever javascript
> representation of the array he wished[1], but the json approach means
> that if the structure of his php generated array changes, the transfer of
> that array into a javascript object is probably robust enough to not need
> "tweaking", and the only changes he's likely to have to make to his
> javascript will be how he uses the modified object, without having to
> worry about restructuring the conversion from the php array to the
> javascript object.
>
> Rgds
>
> Denis McMahon
>

<snip>


Personally, I think a much easier solution would be to just generate the
javascript in the page - no json overhead, no extra calls to the server
or anything else.

As for the structure of the PHP array changing - he'll have the same
problem with his javascript either way - he'll have to change the PHP
code creating the json data and/or the javascript to process it.

But either way, he still needs to know what he wants for his javascript.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to convert this PHP into JavaScript [message #173173 is a reply to message #173171] Fri, 25 March 2011 23:23 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 3/25/2011 5:01 PM, Jerry Stuckle wrote:
> On 3/25/2011 4:51 PM, Denis McMahon wrote:
>> On Fri, 25 Mar 2011 15:22:42 -0400, Jerry Stuckle wrote:
>>
>>> On 3/25/2011 2:59 PM, sheldonlg wrote:
>>>> On 3/24/2011 12:50 PM, Jerry Stuckle wrote:
>>>> > On 3/24/2011 10:23 AM, Oltmans wrote:
>>>> >> Hi PHP gurus, I hope you're doing well.
>>>> >>
>>>> >> I'm trying to convert a PHP script into JavaScript. I'm posting here
>>>> >> because I don't know much PHP and I hope someone among you can help.
>>>> >> Here is the PHP
>>>> >>
>>>> >> array(
>>>> >> 'abc' => '1 AND (2 OR
>>>> >> 3)', // Define how to
>>>> >> use the following criteria
>>>> >> 'def' => array('marketing_campaign_id', 'status', 'status'), //
>>>> >> Filter by these three criteria 'ghi' => array('eq', 'eq',
>>>> >> 'eq')
>>>> >> );
>>>> >>
>>>> >>
>>>> >> I need to convert above into JavaScript object which looks like
>>>> >>
>>>> >> {
>>>> >>
>>>> >> 'abc' : '1 AND (2 OR 3)'
>>>> >> }
>>>> >>
>>>> >>
>>>> >> but I don't know how to convert
>>>> >>
>>>> >> array('marketing_campaign_id', 'status', 'status')
>>>> >>
>>>> >> into equivalent JavaScript. Can someone please let me know how to
>>>> >> convert above into JavaScript? I will really appreciate your help in
>>>> >> this regard. Thanks!
>>>> >
>>>> > If you want to write javascript, you should ask in a javascript
>>>> > newsgroup.
>>>> >
>>>> >
>>>> No Jerry, not this time. He has a PHP array and he wants to use that
>>>> PHP array to generate a script in javascript. That means that knowledge
>>>> of BOTH is required.
>>>>
>>>> This is more properly asked here in this PHP group than in the
>>>> Javascript group. Everyone here also knows at least SOME Javascript.
>>>> The reverse is not true for the Javascript group. People there may not
>>>> know ANY PHP (though most seem to).
>>>>
>>>>
>>> No, Sheldon, he needs to be in comp.lang.javascript - where some of the
>>> people there know PHP.
>>>
>>> The first thing he needs is the appropriate javascript he needs - i.e.
>>> hand coding it. The generating the appropriate javascript from the
>>> array is simple.
>>>
>>> Now, if he would have said "I have this javascript I need to generate
>>> from this PHP array...", I would agree this is more appropriate.
>>
>> It does depend on your viewpoint of what he's asking.
>>
>> My viewpoint is that he has a server side php application that generates
>> a (two dimensional associative) array in php, and that he subsequently
>> wants to use the data in that array client side with javascript running
>> in a website viewers browser.
>>
>> So, I see his problem as being "how do I pass the information contained
>> in this (two dimensional associative) array in my php script on the
>> server into the webpage that I am generating to send to the website
>> viewers client browser so that it can be used by scripts running in a
>> client side context on that web page?"
>>
>> My solution is to create a JSON string representation of his (two
>> dimensional associative) array, and put that string into the heredoc
>> output in a way that the javascript will create a javascript object that,
>> whilst not technically a (two dimensional associative) array, is similar
>> enough to one in structure that he can access the data elements of it in
>> a manner that correlates to the keys in the original php (two dimensional
>> associative) array.
>>
>> Doubtless there are other solutions, if his array always had the same
>> structure and format, he could write code to generate whatever javascript
>> representation of the array he wished[1], but the json approach means
>> that if the structure of his php generated array changes, the transfer of
>> that array into a javascript object is probably robust enough to not need
>> "tweaking", and the only changes he's likely to have to make to his
>> javascript will be how he uses the modified object, without having to
>> worry about restructuring the conversion from the php array to the
>> javascript object.
>>
>> Rgds
>>
>> Denis McMahon
>>
>
> <snip>
>
>
> Personally, I think a much easier solution would be to just generate the
> javascript in the page - no json overhead, no extra calls to the server
> or anything else.
>
> As for the structure of the PHP array changing - he'll have the same
> problem with his javascript either way - he'll have to change the PHP
> code creating the json data and/or the javascript to process it.
>
> But either way, he still needs to know what he wants for his javascript.
>

I just, two days ago, had a need to do just that. What I did was:

print "<script>\n";
print " var foo = new Array();\n";
print " foo[0] = " . $foo[0] . ";\n";
etc. (generating the array for javascript)
print " function myFunc(i) { \n";
print " ...... do stuff with the foo[i] ......\n";
print " }\n";
print "</script\n";

and then have the function myFunc called as needed later in the page.


--
Shelly
Re: How to convert this PHP into JavaScript [message #173174 is a reply to message #173170] Fri, 25 March 2011 23:25 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 3/25/2011 4:56 PM, Thomas 'PointedEars' Lahn wrote:
> Denis McMahon wrote:
>
>> Oltmans wrote:
>>> […] Here is the PHP
>>>
>>> array(
>>> 'abc' => '1 AND (2 OR
>>> 3)', // Define how to use
>>> the following criteria
>>> 'def' => array('marketing_campaign_id', 'status',
>>> 'status'), // Filter by these three criteria
>>> 'ghi' => array('eq', 'eq',
>>> 'eq')
>>> );
>>>
>>>
>>> I need to convert above into JavaScript object which looks like
>>>
>>> {
>>>
>>> 'abc' : '1 AND (2 OR 3)'
>>> }
>>>
>>> […]
>>
>> Here is a display of some PHP source code that generates a document which
>> contains some javascript, and passes an object to that javascript using
>> JSON.
>>
>> http://www.sined.co.uk/tmp/oltmans.htm
>>
>> And here is the output it generates:
>>
>> http://www.sined.co.uk/tmp/oltmans.php
>>
>> Looking at these will probably confuse you, but might instead be of some
>> help.
>
> Version information from the OP being missing, the correct answer is of
> course to use PHP's json_encode() function¹ to generate JSON (JavaScript
> Object Notation)² from the PHP value, which is compatible with all
> statistically significant client-side ECMAScript implementations³ (every
> syntactically valid JSON object string is a syntactically valid ECMAScript
> Object initializer/literal, and every syntactically valid JSON array string
> is a syntactically valid Array initializer/literal; the reverse is not
> true):
>
> <?php echo json_encode(array('abc' => '1 AND (2 OR 3)')); ?>
>
> ______
> ¹<http://php.net/json_encode>
> ²<http://json.org/>
> ³<http://PointedEars.de/scripts/test/es-matrix/#!>
>
>
> PointedEars


This little php program:
<?php
$arr = array('abc'=>1, 'def'=>array('marketing_campaign_id', 'status',
'status'), 'ghi'=>array('eg', 'eq', 'eq'));
$json = json_encode($arr);
print '<pre>'; print_r($arr);print'</pre>';
print 'json endoded = '.$json;
?>

generates this output:
Array
(
[abc] => 1
[def] => Array
(
[0] => marketing_campaign_id
[1] => status
[2] => status
)

[ghi] => Array
(
[0] => eg
[1] => eq
[2] => eq
)

)

json endoded =
{"abc":1,"def":["marketing_campaign_id","status","status"],"ghi":[ "eg","eq","eq"]}

--
Shelly
Re: How to convert this PHP into JavaScript [message #173175 is a reply to message #173173] Fri, 25 March 2011 23:45 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/25/2011 7:23 PM, sheldonlg wrote:
> On 3/25/2011 5:01 PM, Jerry Stuckle wrote:
>> On 3/25/2011 4:51 PM, Denis McMahon wrote:
>>> On Fri, 25 Mar 2011 15:22:42 -0400, Jerry Stuckle wrote:
>>>
>>>> On 3/25/2011 2:59 PM, sheldonlg wrote:
>>>> > On 3/24/2011 12:50 PM, Jerry Stuckle wrote:
>>>> >> On 3/24/2011 10:23 AM, Oltmans wrote:
>>>> >>> Hi PHP gurus, I hope you're doing well.
>>>> >>>
>>>> >>> I'm trying to convert a PHP script into JavaScript. I'm posting here
>>>> >>> because I don't know much PHP and I hope someone among you can help.
>>>> >>> Here is the PHP
>>>> >>>
>>>> >>> array(
>>>> >>> 'abc' => '1 AND (2 OR
>>>> >>> 3)', // Define how to
>>>> >>> use the following criteria
>>>> >>> 'def' => array('marketing_campaign_id', 'status', 'status'), //
>>>> >>> Filter by these three criteria 'ghi' => array('eq', 'eq',
>>>> >>> 'eq')
>>>> >>> );
>>>> >>>
>>>> >>>
>>>> >>> I need to convert above into JavaScript object which looks like
>>>> >>>
>>>> >>> {
>>>> >>>
>>>> >>> 'abc' : '1 AND (2 OR 3)'
>>>> >>> }
>>>> >>>
>>>> >>>
>>>> >>> but I don't know how to convert
>>>> >>>
>>>> >>> array('marketing_campaign_id', 'status', 'status')
>>>> >>>
>>>> >>> into equivalent JavaScript. Can someone please let me know how to
>>>> >>> convert above into JavaScript? I will really appreciate your help in
>>>> >>> this regard. Thanks!
>>>> >>
>>>> >> If you want to write javascript, you should ask in a javascript
>>>> >> newsgroup.
>>>> >>
>>>> >>
>>>> > No Jerry, not this time. He has a PHP array and he wants to use that
>>>> > PHP array to generate a script in javascript. That means that
>>>> > knowledge
>>>> > of BOTH is required.
>>>> >
>>>> > This is more properly asked here in this PHP group than in the
>>>> > Javascript group. Everyone here also knows at least SOME Javascript.
>>>> > The reverse is not true for the Javascript group. People there may not
>>>> > know ANY PHP (though most seem to).
>>>> >
>>>> >
>>>> No, Sheldon, he needs to be in comp.lang.javascript - where some of the
>>>> people there know PHP.
>>>>
>>>> The first thing he needs is the appropriate javascript he needs - i.e.
>>>> hand coding it. The generating the appropriate javascript from the
>>>> array is simple.
>>>>
>>>> Now, if he would have said "I have this javascript I need to generate
>>>> from this PHP array...", I would agree this is more appropriate.
>>>
>>> It does depend on your viewpoint of what he's asking.
>>>
>>> My viewpoint is that he has a server side php application that generates
>>> a (two dimensional associative) array in php, and that he subsequently
>>> wants to use the data in that array client side with javascript running
>>> in a website viewers browser.
>>>
>>> So, I see his problem as being "how do I pass the information contained
>>> in this (two dimensional associative) array in my php script on the
>>> server into the webpage that I am generating to send to the website
>>> viewers client browser so that it can be used by scripts running in a
>>> client side context on that web page?"
>>>
>>> My solution is to create a JSON string representation of his (two
>>> dimensional associative) array, and put that string into the heredoc
>>> output in a way that the javascript will create a javascript object
>>> that,
>>> whilst not technically a (two dimensional associative) array, is similar
>>> enough to one in structure that he can access the data elements of it in
>>> a manner that correlates to the keys in the original php (two
>>> dimensional
>>> associative) array.
>>>
>>> Doubtless there are other solutions, if his array always had the same
>>> structure and format, he could write code to generate whatever
>>> javascript
>>> representation of the array he wished[1], but the json approach means
>>> that if the structure of his php generated array changes, the
>>> transfer of
>>> that array into a javascript object is probably robust enough to not
>>> need
>>> "tweaking", and the only changes he's likely to have to make to his
>>> javascript will be how he uses the modified object, without having to
>>> worry about restructuring the conversion from the php array to the
>>> javascript object.
>>>
>>> Rgds
>>>
>>> Denis McMahon
>>>
>>
>> <snip>
>>
>>
>> Personally, I think a much easier solution would be to just generate the
>> javascript in the page - no json overhead, no extra calls to the server
>> or anything else.
>>
>> As for the structure of the PHP array changing - he'll have the same
>> problem with his javascript either way - he'll have to change the PHP
>> code creating the json data and/or the javascript to process it.
>>
>> But either way, he still needs to know what he wants for his javascript.
>>
>
> I just, two days ago, had a need to do just that. What I did was:
>
> print "<script>\n";
> print " var foo = new Array();\n";
> print " foo[0] = " . $foo[0] . ";\n";
> etc. (generating the array for javascript)
> print " function myFunc(i) { \n";
> print " ...... do stuff with the foo[i] ......\n";
> print " }\n";
> print "</script\n";
>
> and then have the function myFunc called as needed later in the page.
>
>

Sure, I've done similar many times. It's quite a bit easier than trying
to use json.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to convert this PHP into JavaScript [message #173176 is a reply to message #173173] Sat, 26 March 2011 06:03 Go to previous messageGo to next message
Curtis Dyer is currently offline  Curtis Dyer
Messages: 34
Registered: January 2011
Karma: 0
Member
sheldonlg <sheldonlg(at)thevillages(dot)net> wrote:

> On 3/25/2011 5:01 PM, Jerry Stuckle wrote:
>> On 3/25/2011 4:51 PM, Denis McMahon wrote:
>>> On Fri, 25 Mar 2011 15:22:42 -0400, Jerry Stuckle wrote:
>>>
>>>> On 3/25/2011 2:59 PM, sheldonlg wrote:
>>>> > On 3/24/2011 12:50 PM, Jerry Stuckle wrote:
>>>> >> On 3/24/2011 10:23 AM, Oltmans wrote:
>>>> >>> Hi PHP gurus, I hope you're doing well.
>>>> >>>
>>>> >>> I'm trying to convert a PHP script into JavaScript. I'm
>>>> >>> posting here because I don't know much PHP and I hope
>>>> >>> someone among you can help. Here is the PHP

<snip>

>>>> >> If you want to write javascript, you should ask in a
>>>> >> javascript newsgroup.
>>>> >>
>>>> > No Jerry, not this time. He has a PHP array and he wants to
>>>> > use that PHP array to generate a script in javascript. That
>>>> > means that knowledge of BOTH is required.

This is one of those cases in which I feel that cross-posting is
viable. The problem here is that the OP needs advice on how to
generate *quality* target code from PHP. Therefore, quality
JavaScript advice form people who are aware of subtle issues like
automatic semi-colon insertion (ASI), ECMAScript string literal
syntax, etc. are necessary.

<snip>

> I just, two days ago, had a need to do just that. What I did
> was:

I would consider outputting the below outside of PHP tags or
perhaps using heredoc syntax.

> print "<script>\n";
> print " var foo = new Array();\n";

Less verbose would be:

var foo = [];

> print " foo[0] = " . $foo[0] . ";\n";

You give no evidence here that `$foo[0]' is properly escaped to be
included in a string literal. There are important differences
between PHP's and JavaScript's one needs to keep in mind. In
addition to properly escaping quotes and backslashes, one needs to
take care that the JavaScript string literal has no actual line
terminators hard coded into it:

/* Invalid JavaScript string literal */
var foo = "bar
baz";

If I haven't missed anything, one way to escape the output for
JavaScript in PHP might look like:

$escaped = addcslashes($foo[0], "\"\n\r\\'");

<snip>

--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
Re: How to convert this PHP into JavaScript [message #173177 is a reply to message #173174] Sat, 26 March 2011 07:53 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
sheldonlg wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Denis McMahon wrote:
>>> Oltmans wrote:
>>>> […] Here is the PHP
>>>>
>>>> array(
>>>> 'abc' => '1 AND (2 OR
>>>> 3)', // Define how to
>>>> use the following criteria
>>>> 'def' => array('marketing_campaign_id', 'status',
>>>> 'status'), // Filter by these three criteria
>>>> 'ghi' => array('eq', 'eq',
>>>> 'eq')
>>>> );
>>>>
>>>>
>>>> I need to convert above into JavaScript object which looks like
>>>>
>>>> {
>>>>
>>>> 'abc' : '1 AND (2 OR 3)'
>>>> }
>>>> […]
>>>
>>> […]
>>> http://www.sined.co.uk/tmp/oltmans.htm
>>>
>>> And here is the output it generates:
>>>
>>> http://www.sined.co.uk/tmp/oltmans.php
>>> […]
>>
>> Version information from the OP being missing, the correct answer is of
>> course to use PHP's json_encode() function¹ to generate JSON (JavaScript
>> Object Notation)² from the PHP value, […]
>>
>> <?php echo json_encode(array('abc' => '1 AND (2 OR 3)')); ?>
>>
>> ______
>> ¹<http://php.net/json_encode>
>> […]
>
> This little php program:
> <?php
> $arr = array('abc'=>1, 'def'=>array('marketing_campaign_id', 'status',
> 'status'), 'ghi'=>array('eg', 'eq', 'eq'));
> $json = json_encode($arr);
> print '<pre>'; print_r($arr);print'</pre>';
> print 'json endoded = '.$json;
> ?>
>
> generates this output:
> Array
> (
> [abc] => 1
> [def] => Array
> (
> [0] => marketing_campaign_id
> [1] => status
> [2] => status
> )
>
> [ghi] => Array
> (
> [0] => eg
> [1] => eq
> [2] => eq
> )
>
> )
>
> json endoded =
> {"abc":1,"def":["marketing_campaign_id","status","status"],"ghi":
["eg","eq","eq"]}
>

Your point being?

<http://www.netmeister.org/news/learn2quote.html>


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Re: How to convert this PHP into JavaScript [message #173179 is a reply to message #173176] Sat, 26 March 2011 09:28 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Curtis Dyer wrote:

> sheldonlg wrote:
>
> This is one of those cases in which I feel that cross-posting is
> viable. The problem here is that the OP needs advice on how to
> generate *quality* target code from PHP. Therefore, quality
> JavaScript advice form people who are aware of subtle issues like
> automatic semi-colon insertion (ASI), ECMAScript string literal
> syntax, etc. are necessary.

Generally, full ACK. But I think it is no longer necessary in this case.

>> I just, two days ago, had a need to do just that. What I did
>> was:
>
> I would consider outputting the below outside of PHP tags

Exactly.

> or perhaps using heredoc syntax.

I have found heredoc syntax to be tedious with indentation, and editors
incapable of proper syntax highlighting of non-PHP code in heredoc strings,
so I have begun to avoid it.

>> print "<script>\n";
>> print " var foo = new Array();\n";
>
> Less verbose would be:
>
> var foo = [];
>
>> print " foo[0] = " . $foo[0] . ";\n";
>
> You give no evidence here that `$foo[0]' is properly escaped to be
> included in a string literal

It is inefficiently written, too. Consecutive `echo' or `print' statements
are almost always a sign of cluelessness; in this case, the statements
should have been replaced at first by

?><script>
var foo = [
<?php echo $foo[0]; ?>,
/* etc. (generating the array for javascript) */
];

function myFunc(i)
{
/* do stuff with the foo[i] */
}
</script><?php

Note that the Array literal should not have a trailing comma, for ECMAScript
implementations differ there. The global variable should be avoided in the
first place, of course. And there is still no "javascript":

> There are important differences between PHP's and JavaScript's one needs
> to keep in mind.

One being that JavaScript is only one of many implementations of ECMAScript,
a standard for an extensible programming language.

> In addition to properly escaping quotes and backslashes,
> one needs to take care that the JavaScript string literal has no actual
> line terminators hard coded into it:

Unless preceded by backslash, which has been standardized by ECMAScript
Edition 5, but AFAIK cannot be considered safe to date (thanks to Opera).

> If I haven't missed anything, one way to escape the output for
> JavaScript in PHP might look like:
>
> $escaped = addcslashes($foo[0], "\"\n\r\\'");

You have missed json_encode(), which does that *and* safe encoding of other
Unicode characters, independent of the character encoding of the resulting
document.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Re: How to convert this PHP into JavaScript [message #173180 is a reply to message #173177] Sat, 26 March 2011 10:58 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 3:53 AM, Thomas 'PointedEars' Lahn wrote:
> sheldonlg wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> Denis McMahon wrote:
>>>> Oltmans wrote:
>>>> > […] Here is the PHP
>>>> >
>>>> > array(
>>>> > 'abc' => '1 AND (2 OR
>>>> > 3)', // Define how to
>>>> > use the following criteria
>>>> > 'def' => array('marketing_campaign_id', 'status',
>>>> > 'status'), // Filter by these three criteria
>>>> > 'ghi' => array('eq', 'eq',
>>>> > 'eq')
>>>> > );
>>>> >
>>>> >
>>>> > I need to convert above into JavaScript object which looks like
>>>> >
>>>> > {
>>>> >
>>>> > 'abc' : '1 AND (2 OR 3)'
>>>> > }
>>>> > […]
>>>>
>>>> […]
>>>> http://www.sined.co.uk/tmp/oltmans.htm
>>>>
>>>> And here is the output it generates:
>>>>
>>>> http://www.sined.co.uk/tmp/oltmans.php
>>>> […]
>>>
>>> Version information from the OP being missing, the correct answer is of
>>> course to use PHP's json_encode() function¹ to generate JSON (JavaScript
>>> Object Notation)² from the PHP value, […]
>>>
>>> <?php echo json_encode(array('abc' => '1 AND (2 OR 3)')); ?>
>>>
>>> ______
>>> ¹<http://php.net/json_encode>
>>> […]
>>
>> This little php program:
>> <?php
>> $arr = array('abc'=>1, 'def'=>array('marketing_campaign_id', 'status',
>> 'status'), 'ghi'=>array('eg', 'eq', 'eq'));
>> $json = json_encode($arr);
>> print '<pre>'; print_r($arr);print'</pre>';
>> print 'json endoded = '.$json;
>> ?>
>>
>> generates this output:
>> Array
>> (
>> [abc] => 1
>> [def] => Array
>> (
>> [0] => marketing_campaign_id
>> [1] => status
>> [2] => status
>> )
>>
>> [ghi] => Array
>> (
>> [0] => eg
>> [1] => eq
>> [2] => eq
>> )
>>
>> )
>>
>> json endoded =
>> {"abc":1,"def":["marketing_campaign_id","status","status"],"ghi":
> ["eg","eq","eq"]}
>>
>
> Your point being?
>
> <http://www.netmeister.org/news/learn2quote.html>
>
>
> PointedEars

Maybe that you are totally clueless, as always?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to convert this PHP into JavaScript [message #173181 is a reply to message #173180] Sat, 26 March 2011 12:04 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Jerry Stuckle wrote:

> Thomas 'PointedEars' Lahn wrote:
>> sheldonlg wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>>> Denis McMahon wrote:
>>>> > Oltmans wrote:
>>>> >> […] Here is the PHP
>>>> >>
>>>> >> array(
>>>> >> 'abc' => '1 AND (2 OR
>>>> >> 3)', // Define how to
>>>> >> use the following criteria
>>>> >> 'def' => array('marketing_campaign_id', 'status',
>>>> >> 'status'), // Filter by these three criteria
>>>> >> 'ghi' => array('eq', 'eq',
>>>> >> 'eq')
>>>> >> );
>>>> >>
>>>> >> I need to convert above into JavaScript object which looks like
>>>> >>
>>>> >> {
>>>> >> 'abc' : '1 AND (2 OR 3)'
>>>> >> }
>>>> >> […]
>>>> > […]
>>>> <?php echo json_encode(array('abc' => '1 AND (2 OR 3)')); ?>
>>>> […]
>>> […]
>>> <?php
>>> $arr = array('abc'=>1, 'def'=>array('marketing_campaign_id', 'status',
>>> 'status'), 'ghi'=>array('eg', 'eq', 'eq'));
>>> $json = json_encode($arr);
>>> print '<pre>'; print_r($arr);print'</pre>';
>>> print 'json endoded = '.$json;
>>> ?>
>>>
>>> generates this output:
>>> Array
>>> (
>>> [abc] => 1
>>> [def] => Array
>>> (
>>> [0] => marketing_campaign_id
>>> [1] => status
>>> [2] => status
>>> )
>>>
>>> [ghi] => Array
>>> (
>>> [0] => eg
>>> [1] => eq
>>> [2] => eq
>>> )
>>>
>>> )
>>>
>>> json endoded =
>>> {"abc":1,"def":["marketing_campaign_id","status","status"],"ghi":
>>> ["eg","eq","eq"]}
>>>
>>
>> Your point being?
>>
>> <http://www.netmeister.org/news/learn2quote.html>
>
> Maybe that you are totally clueless, as always?

Maybe not, as the presented return value of json_encode() corresponds with
what the OP asked for; only that for some reason sheldonlg used 1 instead of
the '1 AND (2 OR 3)' of the OP. So much for cluelessness.

You want to learn to quote as well.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
Re: How to convert this PHP into JavaScript [message #173182 is a reply to message #173181] Sat, 26 March 2011 12:40 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 8:04 AM, Thomas 'PointedEars' Lahn wrote:

>>> <http://www.netmeister.org/news/learn2quote.html>
>>
>> Maybe that you are totally clueless, as always?
>
> Maybe not, as the presented return value of json_encode() corresponds with
> what the OP asked for; only that for some reason sheldonlg used 1 instead of
> the '1 AND (2 OR 3)' of the OP. So much for cluelessness.
>
> You want to learn to quote as well.
>
>
> PointedEars

Yup, you really have no clue.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to convert this PHP into JavaScript [message #173184 is a reply to message #173182] Sat, 26 March 2011 15:59 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Jerry Stuckle wrote:

> Thomas 'PointedEars' Lahn wrote:
>>>> <http://www.netmeister.org/news/learn2quote.html>
>>> Maybe that you are totally clueless, as always?
>>
>> Maybe not, as the presented return value of json_encode() corresponds
>> with what the OP asked for; only that for some reason sheldonlg used 1
>> instead of the '1 AND (2 OR 3)' of the OP. So much for cluelessness.
>
> Yup, you really have no clue.

Suppose I am somehow wrong suggesting json_encode() as the solution to the
OP's problem, perhaps you would enlighten me, then? It would, after all,
fit your ego, which appears to be the only thing you care about. It's your
chance to hit me really hard!

BTW, you still do not know how to quote properly despite being notified.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Re: How to convert this PHP into JavaScript [message #173186 is a reply to message #173184] Sat, 26 March 2011 18:38 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 11:59 AM, Thomas 'PointedEars' Lahn wrote:
> Jerry Stuckle wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>>> > <http://www.netmeister.org/news/learn2quote.html>
>>>> Maybe that you are totally clueless, as always?
>>>
>>> Maybe not, as the presented return value of json_encode() corresponds
>>> with what the OP asked for; only that for some reason sheldonlg used 1
>>> instead of the '1 AND (2 OR 3)' of the OP. So much for cluelessness.
>>
>> Yup, you really have no clue.
>
> Suppose I am somehow wrong suggesting json_encode() as the solution to the
> OP's problem, perhaps you would enlighten me, then? It would, after all,
> fit your ego, which appears to be the only thing you care about. It's your
> chance to hit me really hard!
>
> BTW, you still do not know how to quote properly despite being notified.
>
>
> PointedEars

Let me correct myself. You have absolutely no fricking clue.

And still you have to balls to keep correcting people because they don't
quote like you wish. Just like the troll you've been found to be in
multiple newsgroups.

Better stand up so you can take a load off your brain.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to convert this PHP into JavaScript [message #173188 is a reply to message #173186] Sat, 26 March 2011 18:53 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Jerry Stuckle wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Jerry Stuckle wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>>> Maybe not, as the presented return value of json_encode() corresponds
>>>> with what the OP asked for; only that for some reason sheldonlg used 1
>>>> instead of the '1 AND (2 OR 3)' of the OP. So much for cluelessness.
>>> Yup, you really have no clue.
>> Suppose I am somehow wrong suggesting json_encode() as the solution to
>> the OP's problem, perhaps you would enlighten me, then? It would, after
>> all, fit your ego, which appears to be the only thing you care about.
>> It's your chance to hit me really hard!
>
> Let me correct myself. You have absolutely no fricking clue. […]

I take it then that you are not actually interested in backing up your
statements as you have nothing to back them up at all, and that you are just
a loudmouth who does not know the first thing about client-side ECMAScript-
based scripting. I wish I could say that I am surprised, but I am not.

Unsurprisingly, you have failed to quote properly again. For the
intellectually challenged: Only the parts relevant to an answer should be
quoted, which usually (and certainly here) excludes signatures.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Re: How to convert this PHP into JavaScript [message #173189 is a reply to message #173181] Sat, 26 March 2011 19:18 Go to previous messageGo to next message
P E Schoen is currently offline  P E Schoen
Messages: 86
Registered: January 2011
Karma: 0
Member
"Thomas 'PointedEars' Lahn" wrote in message
news:1767195(dot)sqQXWTLkxd(at)PointedEars(dot)de...

[snip excessive quoted context]

> You want to learn to quote as well.

Is this not PKB?
http://www.netmeister.org/news/learn2quote2.html#ss2.1

Paul
Re: How to convert this PHP into JavaScript [message #173190 is a reply to message #173188] Sat, 26 March 2011 19:36 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 2:53 PM, Thomas 'PointedEars' Lahn wrote:
> Jerry Stuckle wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> Jerry Stuckle wrote:
>>>> Thomas 'PointedEars' Lahn wrote:
>>>> > Maybe not, as the presented return value of json_encode() corresponds
>>>> > with what the OP asked for; only that for some reason sheldonlg used 1
>>>> > instead of the '1 AND (2 OR 3)' of the OP. So much for cluelessness.
>>>> Yup, you really have no clue.
>>> Suppose I am somehow wrong suggesting json_encode() as the solution to
>>> the OP's problem, perhaps you would enlighten me, then? It would, after
>>> all, fit your ego, which appears to be the only thing you care about.
>>> It's your chance to hit me really hard!
>>
>> Let me correct myself. You have absolutely no fricking clue. […]
>
> I take it then that you are not actually interested in backing up your
> statements as you have nothing to back them up at all, and that you are just
> a loudmouth who does not know the first thing about client-side ECMAScript-
> based scripting. I wish I could say that I am surprised, but I am not.
>
> Unsurprisingly, you have failed to quote properly again. For the
> intellectually challenged: Only the parts relevant to an answer should be
> quoted, which usually (and certainly here) excludes signatures.
>
>
> PointedEars

Nope, I'm not going to try to tell you were you're wrong because you
don't even have the most basic ability to understand why you're wrong
(and Shelly's right). But you have to argue anyway.

I've already learned all you'll do is spout off about unrelated things
and try to change the subject - because you really have no idea what
you're talking about. That's your normal mode of operation.

And before telling other people to quote like YOU think they should (and
BTW, you're full of sheet there, also), YOU should learn to follow your
own advice.

But then that's also typical of trolls.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to convert this PHP into JavaScript [message #173191 is a reply to message #173189] Sat, 26 March 2011 20:02 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
PStechPaul wrote:

> "Thomas 'PointedEars' Lahn" wrote in message
> news:1767195(dot)sqQXWTLkxd(at)PointedEars(dot)de...

It's attribution _line_, not attribution novel. And you better get a real
name.

> [snip excessive quoted context]
>
>> You want to learn to quote as well.
>
> Is this not PKB?

Yes, it is not; read more carefully. What you call "excessive" I call the
minimum necessary to retain the context; the other parts have been replaced
by ellipsises (as it is customary and considered polite when omitting text
in quotations).

The purpose of it was to show that my suggestion, json_encode(), actually
provides what the OP asked for –

| […] JavaScript object which looks like
|
| {
|
| 'abc' : '1 AND (2 OR 3)'
| }

– as associative PHP arrays are (and must be) converted to ECMAScript
Object-literal-compatible JSON values (since ECMAScript implementations like
JavaScript have no built-in notion of associative arrays), whereas
(numerically) indexed PHP arrays are converted to Array-literal-compatible
JSON values. The latter is exactly what the OP asked for when they wrote

| […] to convert
|
| array('marketing_campaign_id', 'status', 'status')
|
| into equivalent JavaScript.

which is

["marketing_campaign_id", "status", "status"]

I do not know what "sheldonlg"'s and Jerry Stuckle's gripe is with this
solution, but until they come up with something substantial, I will just
ignore it.

I am using json_encode() in production environments to make Web applications
more responsive, and I have not noticed any problems beyond those that PHP
has with character encoding in the first place – for example, you have to do

<?php
echo json_encode(array('foo' => 'ba' . utf8_encode(chr(0xA0)) . 'r'));
?>

to get the equivalent

{"foo":"ba\u00a0r"}

since

<?php
echo json_encode(array('foo' => 'ba' . chr(0xA0) . 'r'));
?>

will result in a UTF-8 warning and

{"foo":null}


HTH

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Re: How to convert this PHP into JavaScript [message #173195 is a reply to message #173176] Sun, 27 March 2011 01:38 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 2:03 AM, Curtis Dyer wrote:
> sheldonlg<sheldonlg(at)thevillages(dot)net> wrote:
>
>> On 3/25/2011 5:01 PM, Jerry Stuckle wrote:
>>> On 3/25/2011 4:51 PM, Denis McMahon wrote:
>>>> On Fri, 25 Mar 2011 15:22:42 -0400, Jerry Stuckle wrote:
>>>>
>>>> > On 3/25/2011 2:59 PM, sheldonlg wrote:
>>>> >> On 3/24/2011 12:50 PM, Jerry Stuckle wrote:
>>>> >>> On 3/24/2011 10:23 AM, Oltmans wrote:
>>>> >>>> Hi PHP gurus, I hope you're doing well.
>>>> >>>>
>>>> >>>> I'm trying to convert a PHP script into JavaScript. I'm
>>>> >>>> posting here because I don't know much PHP and I hope
>>>> >>>> someone among you can help. Here is the PHP
>
> <snip>
>
>>>> >>> If you want to write javascript, you should ask in a
>>>> >>> javascript newsgroup.
>>>> >>>
>>>> >> No Jerry, not this time. He has a PHP array and he wants to
>>>> >> use that PHP array to generate a script in javascript. That
>>>> >> means that knowledge of BOTH is required.
>
> This is one of those cases in which I feel that cross-posting is
> viable. The problem here is that the OP needs advice on how to
> generate *quality* target code from PHP. Therefore, quality
> JavaScript advice form people who are aware of subtle issues like
> automatic semi-colon insertion (ASI), ECMAScript string literal
> syntax, etc. are necessary.
>
> <snip>
>
>> I just, two days ago, had a need to do just that. What I did
>> was:
>
> I would consider outputting the below outside of PHP tags or
> perhaps using heredoc syntax.
>
>> print "<script>\n";
>> print " var foo = new Array();\n";
>
> Less verbose would be:
>
> var foo = [];
>
>> print " foo[0] = " . $foo[0] . ";\n";
>
> You give no evidence here that `$foo[0]' is properly escaped to be
> included in a string literal. There are important differences
> between PHP's and JavaScript's one needs to keep in mind. In
> addition to properly escaping quotes and backslashes, one needs to
> take care that the JavaScript string literal has no actual line
> terminators hard coded into it:
>
> /* Invalid JavaScript string literal */
> var foo = "bar
> baz";
>
> If I haven't missed anything, one way to escape the output for
> JavaScript in PHP might look like:
>
> $escaped = addcslashes($foo[0], "\"\n\r\\'");
>
> <snip>
>

It was an EXAMPLE written here to show a method. It was untested and
not necessarily complete. Furthermore, I am one of those whose language
is PHP and know more than a little, but far from expert in javascript.
That is why this is in the PHP group.

--
Shelly
Re: How to convert this PHP into JavaScript [message #173196 is a reply to message #173177] Sun, 27 March 2011 01:43 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 3:53 AM, Thomas 'PointedEars' Lahn wrote:
> sheldonlg wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> Denis McMahon wrote:
>>>> Oltmans wrote:
>>>> > […] Here is the PHP
>>>> >
>>>> > array(
>>>> > 'abc' => '1 AND (2 OR
>>>> > 3)', // Define how to
>>>> > use the following criteria
>>>> > 'def' => array('marketing_campaign_id', 'status',
>>>> > 'status'), // Filter by these three criteria
>>>> > 'ghi' => array('eq', 'eq',
>>>> > 'eq')
>>>> > );
>>>> >
>>>> >
>>>> > I need to convert above into JavaScript object which looks like
>>>> >
>>>> > {
>>>> >
>>>> > 'abc' : '1 AND (2 OR 3)'
>>>> > }
>>>> > […]
>>>>
>>>> […]
>>>> http://www.sined.co.uk/tmp/oltmans.htm
>>>>
>>>> And here is the output it generates:
>>>>
>>>> http://www.sined.co.uk/tmp/oltmans.php
>>>> […]
>>>
>>> Version information from the OP being missing, the correct answer is of
>>> course to use PHP's json_encode() function¹ to generate JSON (JavaScript
>>> Object Notation)² from the PHP value, […]
>>>
>>> <?php echo json_encode(array('abc' => '1 AND (2 OR 3)')); ?>
>>>
>>> ______
>>> ¹<http://php.net/json_encode>
>>> […]
>>
>> This little php program:
>> <?php
>> $arr = array('abc'=>1, 'def'=>array('marketing_campaign_id', 'status',
>> 'status'), 'ghi'=>array('eg', 'eq', 'eq'));
>> $json = json_encode($arr);
>> print '<pre>'; print_r($arr);print'</pre>';
>> print 'json endoded = '.$json;
>> ?>
>>
>> generates this output:
>> Array
>> (
>> [abc] => 1
>> [def] => Array
>> (
>> [0] => marketing_campaign_id
>> [1] => status
>> [2] => status
>> )
>>
>> [ghi] => Array
>> (
>> [0] => eg
>> [1] => eq
>> [2] => eq
>> )
>>
>> )
>>
>> json endoded =
>> {"abc":1,"def":["marketing_campaign_id","status","status"],"ghi":
> ["eg","eq","eq"]}
>>
>
> Your point being?
>
> <http://www.netmeister.org/news/learn2quote.html>
>
>
> PointedEars

To help the OP with an illustration?

What's your problem with that?

--
Shelly
Re: How to convert this PHP into JavaScript [message #173197 is a reply to message #173188] Sun, 27 March 2011 01:47 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 2:53 PM, Thomas 'PointedEars' Lahn wrote:
> Jerry Stuckle wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> Jerry Stuckle wrote:
>>>> Thomas 'PointedEars' Lahn wrote:
>>>> > Maybe not, as the presented return value of json_encode() corresponds
>>>> > with what the OP asked for; only that for some reason sheldonlg used 1
>>>> > instead of the '1 AND (2 OR 3)' of the OP. So much for cluelessness.
>>>> Yup, you really have no clue.
>>> Suppose I am somehow wrong suggesting json_encode() as the solution to
>>> the OP's problem, perhaps you would enlighten me, then? It would, after
>>> all, fit your ego, which appears to be the only thing you care about.
>>> It's your chance to hit me really hard!
>>
>> Let me correct myself. You have absolutely no fricking clue. […]
>
> I take it then that you are not actually interested in backing up your
> statements as you have nothing to back them up at all, and that you are just
> a loudmouth who does not know the first thing about client-side ECMAScript-
> based scripting. I wish I could say that I am surprised, but I am not.
>
> Unsurprisingly, you have failed to quote properly again. For the
> intellectually challenged: Only the parts relevant to an answer should be
> quoted, which usually (and certainly here) excludes signatures.
>
>
> PointedEars

For the record, I am now out of this pissing contest. I didn't intend
to get into one, I refuse to participate. My only aim was to try to
help the OP, so despite the fact that my post was the one that starting
this pissing contest between the two of you, please leave me out of any
future posts on this.

--
Shelly
Re: How to convert this PHP into JavaScript [message #173198 is a reply to message #173190] Sun, 27 March 2011 01:48 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 3:36 PM, Jerry Stuckle wrote:
> On 3/26/2011 2:53 PM, Thomas 'PointedEars' Lahn wrote:
>> Jerry Stuckle wrote:
>>
>>> Thomas 'PointedEars' Lahn wrote:
>>>> Jerry Stuckle wrote:
>>>> > Thomas 'PointedEars' Lahn wrote:
>>>> >> Maybe not, as the presented return value of json_encode() corresponds
>>>> >> with what the OP asked for; only that for some reason sheldonlg
>>>> >> used 1
>>>> >> instead of the '1 AND (2 OR 3)' of the OP. So much for cluelessness.
>>>> > Yup, you really have no clue.
>>>> Suppose I am somehow wrong suggesting json_encode() as the solution to
>>>> the OP's problem, perhaps you would enlighten me, then? It would, after
>>>> all, fit your ego, which appears to be the only thing you care about.
>>>> It's your chance to hit me really hard!
>>>
>>> Let me correct myself. You have absolutely no fricking clue. […]
>>
>> I take it then that you are not actually interested in backing up your
>> statements as you have nothing to back them up at all, and that you
>> are just
>> a loudmouth who does not know the first thing about client-side
>> ECMAScript-
>> based scripting. I wish I could say that I am surprised, but I am not.
>>
>> Unsurprisingly, you have failed to quote properly again. For the
>> intellectually challenged: Only the parts relevant to an answer should be
>> quoted, which usually (and certainly here) excludes signatures.
>>
>>
>> PointedEars
>
> Nope, I'm not going to try to tell you were you're wrong because you
> don't even have the most basic ability to understand why you're wrong
> (and Shelly's right). But you have to argue anyway.

As I stated in a reply I made 15 seconds ago, please leave me out of any
future fighting between the two of you. All I wanted to do was to help
the OP.

>
> I've already learned all you'll do is spout off about unrelated things
> and try to change the subject - because you really have no idea what
> you're talking about. That's your normal mode of operation.
>
> And before telling other people to quote like YOU think they should (and
> BTW, you're full of sheet there, also), YOU should learn to follow your
> own advice.
>
> But then that's also typical of trolls.
>


--
Shelly
Re: How to convert this PHP into JavaScript [message #173199 is a reply to message #173191] Sun, 27 March 2011 01:51 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 4:02 PM, Thomas 'PointedEars' Lahn wrote:
> PStechPaul wrote:
>
>> "Thomas 'PointedEars' Lahn" wrote in message
>> news:1767195(dot)sqQXWTLkxd(at)PointedEars(dot)de...
>
> It's attribution _line_, not attribution novel. And you better get a real
> name.
>
>> [snip excessive quoted context]
>>
>>> You want to learn to quote as well.
>>
>> Is this not PKB?
>
> Yes, it is not; read more carefully. What you call "excessive" I call the
> minimum necessary to retain the context; the other parts have been replaced
> by ellipsises (as it is customary and considered polite when omitting text
> in quotations).
>
> The purpose of it was to show that my suggestion, json_encode(), actually
> provides what the OP asked for –
>
> | […] JavaScript object which looks like
> |
> | {
> |
> | 'abc' : '1 AND (2 OR 3)'
> | }
>
> – as associative PHP arrays are (and must be) converted to ECMAScript
> Object-literal-compatible JSON values (since ECMAScript implementations like
> JavaScript have no built-in notion of associative arrays), whereas
> (numerically) indexed PHP arrays are converted to Array-literal-compatible
> JSON values. The latter is exactly what the OP asked for when they wrote
>
> | […] to convert
> |
> | array('marketing_campaign_id', 'status', 'status')
> |
> | into equivalent JavaScript.
>
> which is
>
> ["marketing_campaign_id", "status", "status"]
>
> I do not know what "sheldonlg"'s and Jerry Stuckle's gripe is with this
> solution, but until they come up with something substantial, I will just
> ignore it.

I have no gripe with your solution. I also have used json_encode in
production environments. It is just that there is also an alternate
method that the OP might prefer. There is more than one way to skin a cat.

>
> I am using json_encode() in production environments to make Web applications
> more responsive, and I have not noticed any problems beyond those that PHP
> has with character encoding in the first place – for example, you have to do
>
> <?php
> echo json_encode(array('foo' => 'ba' . utf8_encode(chr(0xA0)) . 'r'));
> ?>
>
> to get the equivalent
>
> {"foo":"ba\u00a0r"}
>
> since
>
> <?php
> echo json_encode(array('foo' => 'ba' . chr(0xA0) . 'r'));
> ?>
>
> will result in a UTF-8 warning and
>
> {"foo":null}
>
>
> HTH
>
> PointedEars


--
Shelly
Re: How to convert this PHP into JavaScript [message #173200 is a reply to message #173198] Sun, 27 March 2011 01:55 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/26/2011 9:48 PM, sheldonlg wrote:
> On 3/26/2011 3:36 PM, Jerry Stuckle wrote:
>> On 3/26/2011 2:53 PM, Thomas 'PointedEars' Lahn wrote:
>>> Jerry Stuckle wrote:
>>>
>>>> Thomas 'PointedEars' Lahn wrote:
>>>> > Jerry Stuckle wrote:
>>>> >> Thomas 'PointedEars' Lahn wrote:
>>>> >>> Maybe not, as the presented return value of json_encode()
>>>> >>> corresponds
>>>> >>> with what the OP asked for; only that for some reason sheldonlg
>>>> >>> used 1
>>>> >>> instead of the '1 AND (2 OR 3)' of the OP. So much for cluelessness.
>>>> >> Yup, you really have no clue.
>>>> > Suppose I am somehow wrong suggesting json_encode() as the solution to
>>>> > the OP's problem, perhaps you would enlighten me, then? It would,
>>>> > after
>>>> > all, fit your ego, which appears to be the only thing you care about.
>>>> > It's your chance to hit me really hard!
>>>>
>>>> Let me correct myself. You have absolutely no fricking clue. […]
>>>
>>> I take it then that you are not actually interested in backing up your
>>> statements as you have nothing to back them up at all, and that you
>>> are just
>>> a loudmouth who does not know the first thing about client-side
>>> ECMAScript-
>>> based scripting. I wish I could say that I am surprised, but I am not.
>>>
>>> Unsurprisingly, you have failed to quote properly again. For the
>>> intellectually challenged: Only the parts relevant to an answer
>>> should be
>>> quoted, which usually (and certainly here) excludes signatures.
>>>
>>>
>>> PointedEars
>>
>> Nope, I'm not going to try to tell you were you're wrong because you
>> don't even have the most basic ability to understand why you're wrong
>> (and Shelly's right). But you have to argue anyway.
>
> As I stated in a reply I made 15 seconds ago, please leave me out of any
> future fighting between the two of you. All I wanted to do was to help
> the OP.
>
>>
>> I've already learned all you'll do is spout off about unrelated things
>> and try to change the subject - because you really have no idea what
>> you're talking about. That's your normal mode of operation.
>>
>> And before telling other people to quote like YOU think they should (and
>> BTW, you're full of sheet there, also), YOU should learn to follow your
>> own advice.
>>
>> But then that's also typical of trolls.
>>
>
>

You don't have to be in it, Shelly. But since "Pointed Head" brought
you up, I was just pointing out that you are right and he isn't.

You can choose to be a part of the conversation or not. By replying, it
looks like you've chosen to be a part.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to convert this PHP into JavaScript [message #173204 is a reply to message #173199] Sun, 27 March 2011 09:04 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
sheldonlg wrote:

> On 3/26/2011 4:02 PM, Thomas 'PointedEars' Lahn wrote:
>> I do not know what "sheldonlg"'s and Jerry Stuckle's gripe is with this
>> solution, but until they come up with something substantial, I will just
>> ignore it.
>
> I have no gripe with your solution. I also have used json_encode in
> production environments. It is just that there is also an alternate
> method that the OP might prefer. There is more than one way to skin a
> cat.

So, instead of posting only the obvious, that which the proposed
json_encode() solution results in, you should have posted that alternate
solution of yours, because what Denis posted surely is not it.

And will you *please* trim your quotes to the relevant minimum. Proper
quoting really is not rocket science.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
Re: How to convert this PHP into JavaScript [message #173207 is a reply to message #173204] Sun, 27 March 2011 15:42 Go to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 3/27/2011 5:04 AM, Thomas 'PointedEars' Lahn wrote:
> sheldonlg wrote:
>
>> On 3/26/2011 4:02 PM, Thomas 'PointedEars' Lahn wrote:
>>> I do not know what "sheldonlg"'s and Jerry Stuckle's gripe is with this
>>> solution, but until they come up with something substantial, I will just
>>> ignore it.
>>
>> I have no gripe with your solution. I also have used json_encode in
>> production environments. It is just that there is also an alternate
>> method that the OP might prefer. There is more than one way to skin a
>> cat.
>
> So, instead of posting only the obvious, that which the proposed
> json_encode() solution results in, you should have posted that alternate
> solution of yours, because what Denis posted surely is not it.
>
> And will you *please* trim your quotes to the relevant minimum. Proper
> quoting really is not rocket science.

I _did_ post an alternative. Someone (Denis?) then started in depth
criticizing what was only an illustration of a method. That alternative
method was to write a javascript script using PHP's print statement. If
_that_ is what you meant as "incorrect" (meaning the method, not the
minute details), then _YOU_ are incorrect. It works! Ergo, it is not
incorrect.

--
Shelly
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: website developers requirements
Next Topic: Aste - PHP template engine
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 21:31:55 GMT 2024

Total time taken to generate the page: 0.02776 seconds