Monkuar Posted July 8, 2009 Share Posted July 8, 2009 My variable: lV={1:0,1,0,0,0,0,7:0,2,0,1,1,1,8:0,3,0,1,1,1,9:0,4,0,1,1,1,3:1,1,0,1,0,1,4:1,2,1,1,0,1,2:2,1,0,0,0,0,6:2,2,0,1,1,1,5:2,3,0,1,1,1} This is what is spit's out when im pulling it from MYSQL not mysql i mean post data. 1%3A0%2C1%2C0%3B7%3A0%2C2%2C0%3B8%3A0%2C3%2C0%3B9%3A0%2C4%2C0%3B3%3A1%2C1%2C0%3B4%3A1%2C2%2C1%3B2%3A2%2C1%2C0%3B6%3A2%2C2%2C0%3B5%3A2%2C3%2C0 How do i add bracket's so it's like this: lV={1:[0,1,0,0,0,0],7:[0,2,0,1,1,1],8:[0,3,0,1,1,1],9:[0,4,0,1,1,1],3:[1,1,0,1,0,1],4:[1,2,1,1,0,1],2:[2,1,0,0,0,0],6:[2,2,0,1,1,1],5:[2,3,0,1,1,1]} Thanks notice the ['s... How do i add that in my code so it spit's it out with [ and after ] each 6 numberS? Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/ Share on other sites More sharing options...
Monkuar Posted July 8, 2009 Author Share Posted July 8, 2009 I heard this has something to do with ereg replace so i can put [ after X amount of numbers and a , for the output! Help guys i will pay $.. Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870792 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 Can you show the code you're using to process the post? Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870798 Share on other sites More sharing options...
Monkuar Posted July 8, 2009 Author Share Posted July 8, 2009 Can you show the code you're using to process the post? yea, function getObj(o){return gi(o);} function uS() { var v, i; if(lV[cId][3]) lV[cId][2] = (a.secH.checked?1:0); if(lV[cId][4]) lV[cId][0] = a.secL.selectedIndex; if(lV[cId][5]) { v = parseInt(a.secO.value); if(v!=NaN && v) lV[cId][1] = v; } v=""; for(i in lV) v+=(v?";":"")+i+":"+lV[i][0]+","+lV[i][1]+","+lV[i][2]; a.v.value = v; gi("aS").style.display="block"; cS(); } then it does this for my POST FORM: (on whatever settings it is) 1%3A0%2C1%2C0%3B7%3A0%2C2%2C0%3B8%3A0%2C3%2C0%3B9%3A0%2C4%2C0%3B3%3A1%2C1%2C0%3B4%3A1%2C2%2C1%3B2%3A2%2C1%2C0%3B6%3A2%2C2%2C0%3B5%3A2%2C3%2C0 MY WHOLE JAVASCRIPT FILE FOR IT IS: function getObj(o){return gi(o);} function uS() { var v, i; if(lV[cId][3]) lV[cId][2] = (a.secH.checked?1:0); if(lV[cId][4]) lV[cId][0] = a.secL.selectedIndex; if(lV[cId][5]) { v = parseInt(a.secO.value); if(v!=NaN && v) lV[cId][1] = v; } v=""; for(i in lV) v+=(v?";":"")+i+":"+lV[i][0]+","+lV[i][1]+","+lV[i][2]; a.v.value = v; gi("aS").style.display="block"; cS(); } function cS() { if(eSo) eSo.parentNode.removeChild(eSo); eSo = 0; } var eSo = 0, cId=0; function eS(obj, id) { var i,c = obj.parentNode; var fs = c.parentNode; cS(); cId = id; eSo = document.createElement("div"); eSo.className="p3"; var h = ""; if(lV[id][3]) h += "<input name=\"secH\" type=checkbox"+(lV[id][2]?" checked":"")+"> Hide This Section<br>"; if(lV[id][4]) { h += "Display Location: <select name=\"secL\">"; for(i=0;i<3;i++) h += "<option"+(lV[id][0]==i?" selected":"")+">"+locs[i]+"</option>"; h += "</select><br>"; } if(lV[id][5]) { h += "Display Order: <input name=\"secO\" type=text value=\""+lV[id][1]+"\" size=2><br>"; } if(h) { h += "<div class=\"ab\"><a href=\"javascript:uS()\">Update Settings</a></div>"; eSo.innerHTML = h; } if(c.nextSibling) { fs.insertBefore(eSo, c.nextSibling); } else { fs.appendChild(eSo); } } and maybe function gi(i){var itm=null;if(document.getElementById){itm=document.getElementById(i);}else if(document.all){itm=document.all[i];}else if(document.layers){itm=document.layers[i];}return itm;} Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870800 Share on other sites More sharing options...
Monkuar Posted July 8, 2009 Author Share Posted July 8, 2009 I am in need of php that put's [ ] at the beggining and end of each variable when javascript spit's it out. So for example i need: 1:0,1,0;7:0,2,0;8:0,3,0;9:0,4,0;3:1,1,0;4:1,2,1;2:2,1,0;6:2,2,0;5:2,3,0 This is what it spit's out after i Send the Post data, and show it on my profile.. But i need to have the brackets like: 1:[0,1,0,0,0,0],7:[0,2,0,1,1,1],8:[0,3,0,1,1,1],9:[0,4,0,1,1,1],3:[1,1,0,1,0,1],4:[1,2,1,1,0,1],2:[2,1,0,0,0,0],6:[2,2,0,1,1,1],5:[2,3,0,1,1,1] I hope u understand guys, Thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870801 Share on other sites More sharing options...
sasa Posted July 8, 2009 Share Posted July 8, 2009 <?php $test = 'lV={1:0,1,0,0,0,0,7:0,2,0,1,1,1,8:0,3,0,1,1,1,9:0,4,0,1,1,1,3:1,1,0,1,0,1,4:1,2,1,1,0,1,2:2,1,0,0,0,0,6:2,2,0,1,1,1,5:2,3,0,1,1,1}'; $test = preg_replace('/,\d:/',']$0[',$test); $test = preg_replace('/{\d:/','$0[',$test); $test = str_replace('}', '])', $test); echo $test; ?> Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870829 Share on other sites More sharing options...
Monkuar Posted July 8, 2009 Author Share Posted July 8, 2009 <?php $test = 'lV={1:0,1,0,0,0,0,7:0,2,0,1,1,1,8:0,3,0,1,1,1,9:0,4,0,1,1,1,3:1,1,0,1,0,1,4:1,2,1,1,0,1,2:2,1,0,0,0,0,6:2,2,0,1,1,1,5:2,3,0,1,1,1}'; $test = preg_replace('/,\d:/',']$0[',$test); $test = preg_replace('/{\d:/','$0[',$test); $test = str_replace('}', '])', $test); echo $test; ?> Hi thanks! it works on text but if i have a variable like this itdoesnt work $test = "{$info['v']}"; $test = preg_replace('/,\d:/',']$0[',$test); $test = preg_replace('/{\d:/','$0[',$test); $test = str_replace('}', '])', $test); echo $test; ^^ ? Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870843 Share on other sites More sharing options...
thebadbad Posted July 8, 2009 Share Posted July 8, 2009 What does $info['v'] contain? Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870875 Share on other sites More sharing options...
Monkuar Posted July 8, 2009 Author Share Posted July 8, 2009 What does $info['v'] contain? 1:0,1,0;7:0,2,0;8:0,3,0;9:0,4,0;5:0,5,0;3:1,1,0;4:1,2,0;2:2,1,0;6:3,1,1 Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870881 Share on other sites More sharing options...
sasa Posted July 8, 2009 Share Posted July 8, 2009 $test = "{$info['v']}"; $test = preg_replace('/;\d:/',']$0[',$test);//change , to ; $test = preg_replace('/^\d:/','$0[',$test);//change ( to ^ (start of string) $test .= ']'; // ad ] to end echo $test; Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870889 Share on other sites More sharing options...
thebadbad Posted July 8, 2009 Share Posted July 8, 2009 @OP FYI, curly brackets around variables inside double quotes are part of the syntax and not part of the string. That's one reason the code didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/#findComment-870891 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.