Jump to content

lindm

Members
  • Posts

    199
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lindm's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Having problems creating the object structure. I want a structure like this: { "BFO": { "1": { "text1": "100", "text2": "200", "text3": "300" }, "2": { "text1": "400", "text2": "500", "text3": "600" } } } I am creating the object with an each iteration in jquery: function objects() { var BFO = new Object(); BFO["BFO"] = new Object(); $("tr").each(function(i) { BFO["BFO"][i] = new Object(); BFO["BFO"][i]["text1"]="test"; BFO["BFO"][i]["text2"]="test"; BFO["BFO"][i]["text3"]="test"; }); This generates: {"BFO":[{"text1":"test","text2":"test","text3":"test"},{"text1":"test","text2":"test","text3":"test"}]} } } Almost there but missing the 1, 2 etc and there are [] characters I don't need. Any help to complete appreciated.
  2. I have the following object: var data={ 'ID1':{ field1: 'selector1', field2: 'Text', field3: 'Text1' }, 'ID2':{ field1: 'selector1', field2: 'Text', field3: 'Text2' }, 'ID3':{ field1: 'selector2', field2: 'Text', field3: 'Text3' }, 'ID4':{ field1: 'selector2', field2: 'Text', field3: 'Text4' } }; How would I sum/join all the field3 nodes for each unique field1 node? So for instance the sum/join of selector1 would be "Text1Text2" and for selector2 "Text3Text4". Thanks
  3. Understand your point and appreciate your time and suggested solution. Thought by only needing the answer for merging two arrays, I would handle the problem of the one array. Tried your solution and it seems to work well. Many thanks!
  4. Works perfect. Minor point. I missed that the two arrays to be merged are actually part of the same array. Could this be handled easily? ARRAY Array ( [uB] => Array ([0] => Array ( [1070] => 750000.00 [1079] => -750000.00 ) ) ([-1] => Array ( [1079] => -450000.00 ) ) ) Should become Array ( [uB] => Array ( [1070] => Array ( [0] => 750000 [-1] => 0 ) [1079] => Array ( [0] => -750000 [-1] => -450000 ) ) )
  5. Stuck on merging two arrays: Got the following to arrays: ARRAY1 Array ( [uB] => Array ([0] => Array ( [1070] => 750000.00 [1079] => -750000.00 ) ) ) ARRAY2 Array ( [uB] => Array ([-1] => Array ( [1079] => -450000.00 ) ) ) Want them to merge to the following array (important as you can see that if a key is missing in one array but exists in the other it is created with the value 0) CREATED ARRAY Array ( [uB] => Array ( [1070] => Array ( [0] => 750000.00 [-1] => 0.00 ) [1079] => Array ( [0] => -750000.00 [-1] => -450000.00 ) ) )
  6. Aa alright. Just curious your second suggestion: split on any spaces except those within double-quote delimited phrases, is that a simple regex?
  7. Preferably the double quotes should be removed. As for your suggestions the best would be only the first two spaces would be the best split solution.
  8. Need help figuring out the expression to split the following string in the two first spaces: #TEXT1 1234 "Text text text text" Should become: #TEXT1 1234 Text text text text
  9. I have the function below to check if all form text fields of the selection are either zero or nothing. I realize it has the side effect that if field1 is 1000 and field2 is -1000 the functions returns the class value, which is not the purpose. Any suggestion for a script to check each text field individually it is either zero or contains nothing. If this is true for the arguments it returns the class value. Perhaps using an absolute value? function rowx() { $num = func_num_args(); //antal args $total = 0; for( $i = 0; $i < $num; ++$i ) { $total += func_get_arg($i); } if ($total = 0 || $total =='') return 'class="h"'; }
  10. Is there an way to make sure that a word in bold and the same word in normal have the same width?
  11. Great! Disabling magic quotes solved it.
  12. I read somewhere that magic_quotes will be permanently on in php6..is that correct?
  13. I have the following array which contains trailing slashes I need to remove. What is the best way to accomplish this? Array ( [Field1] => A [Field2] => Test [Field3] => öööö \'\')
  14. lindm

    preg_replace

    Solved it. $string = ' <html> <body> <table> <tr> <td><input name="KRRfield1" type="text" class="fb" id="KRRfield1" value="" /></td> <td><input name="KRRfield2" type="text" class="fb fy" id="KRRfield2" value="" /></td> <td><input name="RRfield3" type="text" class="fb" id="RRfield3" value="" /></td> <td><input name="RRfield4" type="text" class="fb fy" id="RRfield4" value="" /></td> </tr> </table> </body> </html>'; $pattern='/(<input name="KRR)(.+)(type="text" class=")(.+)(")(.+)(id=")(.+)(" value)(.+)(\/>)/'; //$pattern='/<input name="KRR.+\/>/'; $replacement="'.field($8,$4).'"; echo preg_replace($pattern, $replacement, $string);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.