Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7635303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:23:58+00:00 2026-05-31T07:23:58+00:00

please refer to the code below. $dArr = ‘<script>document.write(volunteerDist);</script>’; $dArr gets the value of

  • 0

please refer to the code below.

$dArr = '<script>document.write(volunteerDist);</script>';

$dArr gets the value of volunteerDist. echo $dArr prints the value 4.1,9.4,2.3,4.7,9.1,14.7,3.2,7.1,4.1,0.5

I wanted to split this into elements in an Array so I used:

$dArr = preg_split("/,/", $dArr);

But $dArr is an array with only one element, which is all of the values.. meaning no preg_split took place. I also tried

$temp=explode(",", $dArr);

but still did not work.

I tried to paste the value (i.e. the numbers above) and preg_split it directly

$temp=explode(",", '4.1,9.4,2.3,4.7,9.1,14.7,3.2,7.1,4.1,0.5');

and it was successful. What is wrong? TAKE NOTE that when I echo $dArr, the numbers are printed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:23:59+00:00Added an answer on May 31, 2026 at 7:23 am

    You are mixing server side and client side code and logic here.

    You see the “correct” output because of the document.write method that writes the output to the browser.

    You can’t interact directly with client side variable in a server side code.

    You will have to either use AJAX to send the client side value to the server, or parse it in the client side:

    <script type="text/javascript">
    var dArr = volunteerDist.split(",");
    for (var i = 0; i < dArr.length; i++)
       document.write(dArr[i] + "<br />");
    </script>
    

    Edit: although I’m not PHP developer, reading some other posts gave me enough sample codes.

    To send the value of the client side volunteerDist variable to PHP and save to database, first of all include jQuery in your code:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    

    Now have this somewhere after the variable is defined and created:

    <script type="text/javascript">
    $.ajax({
        type: "POST",
        url: "yourpagehere.php",
        data: "volunteerDist=" + volunteerDist,
        dataType: "html"
    });
    </script>
    

    And to read this data and add to database:

    <?php
        $volunteerDist = $_POST['volunteerDist'];
        if(isset($volunteerDist)) {
            $dArr = preg_split("/,/", $volunteerDist);
            foreach($dArr as $volunteer) {
                $sql = "INSERT INTO TableName (fieldname) VALUES ('".$volunteer."')";
                mysql_query($sql) or die(mysql_error());
            }
        }
    ?>
    

    Of course, you need to change the page name, table name and field name to your real values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please refer to the code below, when I comment in either of the commented
Please refer to the Java code below: class Base{ Base(){ System.out.println(Base Constructor); method(); }
Please refer to the below code Specialized function in non specialized Template class Is
Please refer to the below jsfiddle code snippet: http://jsfiddle.net/JLXs5/3/ When the user clicks here,
Please refer to my code below. When optimization in IAR MSP430 compiler is set
How can I enumerate through an IDictionary? Please refer to the code below. public
Please refer the below code. I want the boxes for Blue and all other
Code for the below test: http://jsfiddle.net/fXdjm/ Questions about line heights: Please refer first box.
I'm creating a bash script that will load CSV files using SQL*Loader. Please refer
I have an NSArray output. please refer below. I want to sort based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.