Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

Using jQuery I can generate a string like this on a HTML document :

num0=500356,num1=853734,num2=981608,num3=795915,num4=824111,num5=831158,num6=364091,num7=368537,num8=410001

This data is not in a form or input HTML tag. It is a string assigned to a variable.

Is there a way to capture this string using javascript and PHP and then insert the numX into a mysql db such as? The db will have fields of num0, num1, num2, num3, num4, num5, num6, num7, num8

num0=500356
num1=853734
num2=981608
num3=795915
num4=824111
num5=831158
num6=364091
num7=368537
num8=410001

Thank you for any help.

share|improve this question
    
your question si way too open ended and it doesn't deal with a problem but a lack of skill to do it. you should consider clarifying a little more. Altho people can and will help you with this matter no one will solve it for you. so make sure you have the necessary skills to produce the anser based on the help provided. – Danilo Kobold Feb 5 '13 at 23:58
    
Where in the document is this string? If it is free-floating, do you mean it is just text (such as in a <p> tag)? Do you need to retrieve it from the document first, or can we assume that it can be read easily and you just need to know how to process it? – halfer Feb 6 '13 at 0:02
    
@halfer, it can be generated so it is assigned to a variable. Yes, it can be placed in a <div> or <p> tag. – none Feb 6 '13 at 1:59
    
Assigned to a JS variable? OK, convert it into a PHP array and do var myJsArray = <?php echo json_encode($myPhpArray) ?>; in your HTML output, inside a <script> block. – halfer Feb 6 '13 at 10:20
$ar = explode("=", $var);
$ar[0] // num0
$ar[1] // 500356
$ar[2] // num1
$ar[3] // 853734
share|improve this answer
    
No, exploding on = will give you num0, 500356,num1, 853734,num2 etc - probably not what you want! The trick is to explode on the comma first, and then for each pair (num0=500356), explode on the = afterwards. – halfer Feb 6 '13 at 0:00

Yes, it is possible.

If the document is in your server you can just make an ajax call when this parameters are available and insert it to your database using php.

If they are on another server you just need to make a php script to fetch em and insert.

share|improve this answer
    
Hi, ok, I figured out how to do it in a new way, thanks for your suggestions. – none Feb 6 '13 at 4:34

I m not sure but you can try this .

$str = explode(",","num0=500356,num1=853734,num2=981608,num3=795915,num4=824111,num5=831158,num6=364091,num7=368537,num8=410001");

foreach($str as $s){
    echo "<pre>";
    print_r($s);
}

It would be output something like this.

num0=500356
num1=853734
num2=981608
num3=795915
num4=824111
num5=831158
num6=364091
num7=368537
num8=410001
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.