forumnz
-
Posts
735 -
Joined
-
Last visited
Posts posted by forumnz
-
-
I'm really trying
It's just so difficult for me.
Would I do some sort of loop now?
-
Thanks Ken2k7
I modified one of your lines to read:
<?php $e = '[{"field3":66,"field4":5,"field1":"ggg","field2":"g","field5":"h","field6":"h","field7":"hh","id":"1"},{"field3":66,"field4":5,"field1":"ggg","field2":"g","field5":"h","field6":"h","field7":"hh","id":"1"}]'; ?>
Which is basically 2 sets of data.
And the output is:
array(2) { [0]=> array( { ["field3"]=> int(66) ["field4"]=> int(5) ["field1"]=> string(3) "ggg" ["field2"]=> string(1) "g" ["field5"]=> string(1) "h" ["field6"]=> string(1) "h" ["field7"]=> string(2) "hh" ["id"]=> string(1) "1" } [1]=> array( { ["field3"]=> int(66) ["field4"]=> int(5) ["field1"]=> string(3) "ggg" ["field2"]=> string(1) "g" ["field5"]=> string(1) "h" ["field6"]=> string(1) "h" ["field7"]=> string(2) "hh" ["id"]=> string(1) "1" } }
Which is fine (I believe). What would I need to do now?
Much appreciated
-
This is what I have for the quotes problem:
<?php $str = $data; $str = substr($str, 1, strlen($str) - 2); $str = preg_replace("/([a-zA-Z0-9_]+?):/" , "\"$1\":", $str); // fix left side $str = preg_replace("/:(^false^true[a-zA-Z_]+[a-zA-Z0-9_]*)/", ":\"$1\"", $str); // fix right side $data = json_decode($str, true); $data = print_r($data); ?>
Still returns 1 though..?
Why would that be?
I do want to store them in a database but I need to get the data into an array for that don't I?
-
Yes it returns 1. It says that if the string is invalid, I returns 1 or NULL.
I'm trying to add double quotes, but not doing well.
-
Thanks, but as you can see there are numbers not enclosed in double quotes. So that work work?
-
Hey
I have a JS script that POSTs this:
[{"field3":66,"field4":5,"field1":"ggg","field2":"g","field5":"h","field6":"h","field7":"hh","id":"1"},{"field2":"cgh","field4":73377,"field3":770}]
to a PHP file.
What can I do to insert that information into a database?
Note that the data between {} is it's own row.
Basically, how can I get that into some sort of suitable array?
-
I have a string "Hello 123 World 456" (example).
Is there a function I can use to add speech marks "" outside numbers, so that same line would read:
"Hello "123" World "456"".
Thanks
-
Which function should I use to replace [ with " in a string?
Thanks
-
Thanks xenophobia - it helps a lot.
How can I rearrange the output to suit?
Currently it is:
Array ( [0] => stdClass Object ( [field1] => a [field2] => b ) [1] => stdClass Object ( [field1] => a2 [field2] => b2 ) )
Thanks
-
How can I separate these sets of data in this array so that they can be inserted into a database?
Array ( [0] => stdClass Object ( [field1] => a [field2] => b ) [1] => stdClass Object ( [field1] => a2 [field2] => b2 ) )
Would I use the [0] and [1]? Sorry for the question, but if someone can point me in the right direction I am more than happy to try to work it out for myself
Thank you
-
Thank you
-
Yes thank you Ken2k7
I just did that (before your comment), but I still only get "Array"
Why?
Thanks ???
-
I am trying to echo the output of a script that posts to a PHP file.
<?php $data = $_POST['data']; $form = $_POST['form']; $data = stripslashes($data); $data = var_dump(json_decode($data, true)); echo $data;
It displays nothing.. why is this?
-
Thanks but what I meant was that the JS posts the data, and the output is as above. I think I may have to refer to the JS, but what would I need to write in the PHP form, to 'retrieve' the POSTed data and put it into a variable?
-
Ok that all makes sense so far - I just have one question:
The script outputs as above, but how do I take the POSTed code and place it into a variable?
Thanks
-
Thanks Ken2k7! I'll do that now
-
In PHP
Is that possible?
-
I have a script that outputs data like this:
{success: true, data: [{"id":"1","fld1":"text","fld2":"text","fld3":"text","fld4":"text","fld5":"text","fld6":"text","fld7":"text","fld8":"text"}, {"id":"2","fld1":"text","fld2":"text","fld3":"text","fld4":"text","fld5":"text","fld6":"text","fld7":"text","fld8":"text"}], form: {"fld9":"text","fld10":"text","fld11":"text","fld12":"text"}}
How can turn that first part of it (the lines that start with id) into an array?
Thanks a lot
-
-
I try to go to my website and it just displays the source code. And its screwed:
<�!�D�O�C�T�Y�P�E� �h�t�m�l� �P�U�B�L�I�C� �"�-�/�/�W�3�C�/�/�D�T�D� �H�T�M�L� �4�.�0�1�
Why?
-
No way! I didn't think that would work either.. but it did! Thanks heaps DarkSuperHero!!
Sam
-
$ik is an md5 string (so 32 chars long)
$to is a text string (eg White House)
$date is text with slashes
The rest are similar, with $tax being from a list (value might be i or e)
What could it be?
-
Is to reserved?
-
I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to, date, due_date, inv_number, ref, tax_incl) VALUES ('e878dca5c96oa38a815cf915' at line 1
And this is the code:
<?php mysql_query("INSERT INTO table (hash_key, inv_key, to, date, due_date, inv_number, ref, tax_incl) VALUES ('$hk', '$ik', '$to', '$date', '$due', '$inv_num', '$ref', '$tax')")or die(mysql_error()); ?>
What's wrong with it?
Thanks
What can I do with this string?
in PHP Coding Help
Posted
Ok so the output now is basically the VALUES and I really just need to put that variable into the database query?