0

I have this PHP Code...

foreach($valoresa as $cada)
    $listaDatos[$c++] = array('Date.UTC(' . date("Y", strtotime($cada['reading_date'])) . ',' . date("m", strtotime($cada['reading_date'])) . ',' . date("d", strtotime($cada['reading_date'])) . ',' . date("H", strtotime($cada['reading_date'])) . ',' . date("i", strtotime($cada['reading_date'])) . ',' . date("s", strtotime($cada['reading_date'])) . ')', floatval($cada['value']));

Then mixing JS and PHP:

{
    name: '<?php echo $nombreDato; ?>',
    yAxis: <?php echo $yAxis++; ?>,
    data: <?php echo json_encode($listaDatos); ?>
},

This is the result:

data: [["Date.UTC(2013,06,26,16,03,35)",0],["Date.UTC(2013,06,26,16,04,35)",1],["Date.UTC(2013,06,26,16,06,35)",0]]

I want this: (Without any quote)

data: [[Date.UTC(2013,06,26,16,03,35),0],[Date.UTC(2013,06,26,16,04,35),1],[Date.UTC(2013,06,26,16,06,35),0]]

Why am I do this? If I do something like this:

foreach($valores01 as $cada)
    $listaDatos[$c++] = array(strtotime($cada['reading_date']) * 1000, floatval($cada['value']));

The highcharts is recognizing the data date, 2 hours earlier than original, and I just want to test with Date.UTC() because original examples of highcharts do it like this: http://jsfiddle.net/JNkRR/

FIXED:

I fixed with the @nnnnnn tip, it very simple, i was thinking about a any json php function or something, but it was simplier using str_replace() php function:

<?php
    $datosFinales = json_encode($listaDatos);
?>
{
    name: '<?php echo $nombreDato; ?>',
    yAxis: <?php echo $yAxis++; ?>,
    data: <?php echo str_replace("\"", "", $datosFinales); ?>
},
6
  • JSON doesn't support quotes. Commented Jun 27, 2013 at 14:18
  • So, it is doing by itself, how can I do in order to remove those quotes. Commented Jun 27, 2013 at 14:19
  • 2
    You could do a string replace in your PHP code to change each " to an empty-string. Commented Jun 27, 2013 at 14:22
  • possible duplicate of Prevent quoting of certain values with PHP json_encode() Commented Jun 27, 2013 at 14:23
  • Well JSON does not support calling methods/functions so how would it be possible to begin with? Commented Jun 27, 2013 at 14:25

1 Answer 1

0

I fixed with the @nnnnnn tip, it very simple, i was thinking about a any json php function or something, but it was simplier using str_replace() php function:

<?php
    $datosFinales = json_encode($listaDatos);
?>
{
    name: '<?php echo $nombreDato; ?>',
    yAxis: <?php echo $yAxis++; ?>,
    data: <?php echo str_replace("\"", "", $datosFinales); ?>
},
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.