Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/165141-how-to-put-a-after-xx-amount-of-numbers/
Share on other sites

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;}

 

 

 

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.. :)

<?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;
?>

<?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;

 

^^ ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.