1

I tryed to remove the quote from my json output, but nothing work...

1 => array(

           'y' => str_replace('"','',$behaviour[5]['wcount']),
           'name' => 'Slice Name B'
        ),

Output

{"y":"3","name":"Slice Name B"}

I need to remove the string "3"

I tryed str_replace('"','',$behaviour[5]['wcount']) and str_replace("'","",$behaviour[5]['wcount']);

Someone can help me please ?

2
  • have you tried casting that to an int? Commented Aug 15, 2011 at 14:49
  • What about str_replace(chr(34), '', $behaviour[5]['wcount'])? Or what @krcko says. Try type casting Commented Aug 15, 2011 at 14:50

2 Answers 2

4

Try this instead:

1 => array(
           'y' => intval($behaviour[5]['wcount']),
           'name' => 'Slice Name B'
        ),
Sign up to request clarification or add additional context in comments.

Comments

3

If you're running PHP 5.3.3. or better, you can pass JSON_NUMERIC_CHECK to json_encode which should do what you want:

$encoded = json_encode($data, JSON_NUMERIC_CHECK);

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.