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 #173170 is a reply to message #173151] Fri, 25 March 2011 20:56 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
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.)
[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: Sat Nov 23 01:22:34 GMT 2024

Total time taken to generate the page: 0.05793 seconds