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 #173191 is a reply to message #173189] Sat, 26 March 2011 20:02 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
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
[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: Thu Nov 28 12:09:36 GMT 2024

Total time taken to generate the page: 0.06225 seconds