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
Return to the default flat view Create a new topic Submit Reply
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 message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma:
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: website developers requirements
Next Topic: Aste - PHP template engine
Goto Forum:
  

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

Current Time: Sun Nov 24 18:27:13 GMT 2024

Total time taken to generate the page: 0.04382 seconds