alecthorne Posted October 29, 2012 Share Posted October 29, 2012 Beginners question, I know. I have a variable $name (in this case 311) This needs to be inserted into another variable named param_title, so the result returns '{"metadata.title": "311", I have tried this with the following, but it does not return a result $params_title="'{"metadata.title":\"$name","; What am I doing wrong?? Thanks, Alec Link to comment https://forums.phpfreaks.com/topic/270050-setting-a-variable/ Share on other sites More sharing options...
Christian F. Posted October 29, 2012 Share Posted October 29, 2012 If you take a look in the PHP manual on strings, I think you should be able to figure it out yourself. Take a close look at how the examples are done, and then compare them to your code. Though, by the looks if the code, it seems you might be looking for arrays and json_encode () as well. In any case, I highly recommend reading through the PHP manual and sinking your teeth into some PHP tutorials. Link to comment https://forums.phpfreaks.com/topic/270050-setting-a-variable/#findComment-1388552 Share on other sites More sharing options...
alecthorne Posted October 30, 2012 Author Share Posted October 30, 2012 Christian, Thanks for the pointer. I worked in the following format $params_title="'{\"metadata.title\": \"{$name}\","; Thanks!! Alec Link to comment https://forums.phpfreaks.com/topic/270050-setting-a-variable/#findComment-1388857 Share on other sites More sharing options...
ManiacDan Posted October 30, 2012 Share Posted October 30, 2012 If you're building a json string (for javascript) then you're doing it the long, complicated, and incorrect way. Christian showed you json_encode, you'll probably want to switch to that at some point. Link to comment https://forums.phpfreaks.com/topic/270050-setting-a-variable/#findComment-1388860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.