FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » values not changing
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: values not changing [message #181564 is a reply to message #181561] Tue, 21 May 2013 22:30 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:

> The data you are assembling looks like json data. For json data, you need
> to quote the attribute name string. The json needs double quoted strings,
> so as you also need to use php double quoted strings to preserve variable
> substitution, you need to use escaped double quoted strings for the json
> string values.
>
> echo "{\"image\":\"\",";
> echo "\"title\":\"{$vid[0]}\",";
> echo "\"file\":\"http://www.youtube.com/watch?v={$vid[2]}\",";
> echo "\"description\":\"{$year} # {$number} - {$vid[1]}\"},";

Assuming JSON, it is much better (if not even the only *correct* way) to
write

echo json_encode(array(
'image' => '',
'title' => $vid[0],
'file' => "http://www.youtube.com/watch?v={$vid[2]}",
'description' => "{$year} # {$number} - {$vid[1]}"
));

Because you cannot simply insert arbitrary strings in a generated string
literal and hope the outcome will be correct JSON; *at least* you would have
to escape slashes in the inserted strings, and you do not have to do that by
yourself if you use json_encode() in the first place. AISB.


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
Previous Topic: insert PDF table in database
Next Topic: Got it working finally
Goto Forum:
  

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

Current Time: Sat Nov 30 11:56:42 GMT 2024

Total time taken to generate the page: 0.04706 seconds