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 #173177 is a reply to message #173174] Sat, 26 March 2011 07:53 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
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
[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: Tue Nov 26 21:49:48 GMT 2024

Total time taken to generate the page: 0.07469 seconds