hi frnds..

var headline = document.getElementById("headline");
	var content = document.getElementById("content");
	var data = "headline=" + headline + "&content=" + content;
    xmlhttp.open("POST","newspost.php",true); 
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(data);

i post data in this way...
n the next page i need to retrieve data ..

$d=$_post['data'];

echo $d;

output is combination of both values....
i need to split data as headline,content....plz give me some suggestions..

Simply use the following:

$d=explode('&content=',$_post['data']);

echo $d[0];
echo "<hr>";
echo $d[1];

Simply use the following:

$d=explode('&content=',$_post['data']);

echo $d[0];
echo "<hr>";
echo $d[1];

Hi cwarn..
Thanks 4 ur quick reply.
in this way i got empty values....

i have another doubt....here i take only two values.in case i need to take more no.of values, how can i split values by using EXPLODE function...

The explode function basically just splits the string where certain character appear and in this case I chose to split wherever the occurance of &content= appears. So if you have another occurance of &content= then it will split it again. But if you want a totally different set of characters to be split then you would use preg_split like the following:

$d=preg_split('/(\&content\=|\&value3\=|\&value4\=)/i',$_post['data']);

echo $d[0];
echo "<hr>";
echo $d[1];
echo "<hr>";
echo $d[2];
echo "<hr>";
echo $d[3];
echo "<hr>";
echo $d[4];

Also with preg_split you can make it case-insensitive like I did above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.