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 #173199 is a reply to message #173191] Sun, 27 March 2011 01:51 Go to previous messageGo to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma:
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
[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 00:46:55 GMT 2024

Total time taken to generate the page: 0.04998 seconds