title: PHP output JSON Web Service charset UTF-8 error
body: <p>I am hosting a web service in JSON output by PHP.</p>
  
  <p>I have <strong>Hebrew</strong> data set in DB and I am posting this as an output to Web service.</p>
  
  <p>When I post the data initially it output the result as follows:</p>
  
  <p><strong>JSON:</strong></p>
  
  <pre><code>{
      "tasklist": [
          {
              "customerID": "9936",
              "name": "×˜×¨ ××¨×ž×” ×™×–×•× ×•×‘×™× ×•×™ ×‘×¢"×ž",
              "cargo":"××‘×¨×¨",
              "destination":"×ž×›×¨", 
              "quantity":"1.000000",
              "startdate":"03/01/201300: 00: 00" 
          }
                 ]
  }
  </code></pre>
  
  <p>But this <code>"××‘×¨×¨"</code> can be readable by Android/Iphone parser and convert it to original Hebrew. But i faced Error in  <code>"name": "×˜×¨ ××¨×ž×” ×™×–×•× ×•×‘×™× ×•×™ ×‘×¢"×ž",</code>. where <code>"</code> is in between the string so the JSON is not valid and shows error!</p>
  
  <p><img src="https://i.stack.imgur.com/rtapp.png" alt="enter image description here"> </p>
  
  <p>To Over come this issue I used <code>UTF-8</code> to convert <code>"××‘×¨×¨"</code> this to Hebrew <code>"נברר"</code>. But in this case too the problem remains same:</p>
  
  <p><strong>PHP:</strong></p>
  
  <blockquote>
    <p>header('Content-type: text/html; charset=UTF-8');</p>
  </blockquote>
  
  <p><strong>JSON:</strong></p>
  
  <pre><code>{
      "tasklist": [
          {
              "customerID": "9936",
              "name": "טר ארמה יזום ובינוי בע"מ",
              "cargo":"נברר",
              "destination":"מכר",
              "quantity":"1.000000",
              "startdate":"03/01/201300: 00: 00"
          }
                  ]
  }
  </code></pre>
  
  <p>But still the problem remains:</p>
  
  <p><img src="https://i.stack.imgur.com/bpVE2.png" alt="enter image description here"></p>
  
  <p>Also in some case I am getting this <code>�</code> because of using UTF-8</p>
  
  <pre><code>"name":"מחצבות כפר גלעדי-חומרי מ�"
  </code></pre>
  
  <ul>
  <li>How can I overcome this issue?</li>
  <li>Is there any other specific encode I need to use?</li>
  </ul>
  
  <p>Note: The data cannot be changes in Database The solution should be while output to JSON.</p>
  
  <p>How the data stored in DB is shown below:</p>
  
  <blockquote>
    <p>name</p>
    
    <p>×ž×—×¦×‘×•×ª ×›×¤×¨ ×’×œ×¢×“×™-×—×•×ž×¨×™ ×ž×</p>
  </blockquote>
  
  <p>My PHP Script which output JSON:</p>
  
  <pre><code>&lt;?php
  
  //My DB connection and Query comes here
  
  $jsontext = '{"tasklist":[';
  while($row = mysql_fetch_array($queryExe)){
  $jsontext .= '{"customerID":"'.$row['AUTO_ID'].'",';
  $jsontext .='"name":"'.$row['Customer_Name'].'",';
  $jsontext .='"cargo":"'.$row['Type_of_Cargo'].'",';
  $jsontext .='"destination":"'.$row['Destination'].'",';
  $jsontext .='"quantity":"'.$row['Quantity'].'",';
  $jsontext .='"startdate":"'.$row['startdate'].'"},';
  }
  $jsontext = substr_replace($jsontext, '', -1); // to get rid of extra comma
  $jsontext .= "]}";
  
  header('Content-type: text/html; charset=UTF-8');
  
  //Output the final JSON
  echo $jsontext;
  
  ?&gt;
  </code></pre>
  
  <p>Thank you for your help in advance!</p>
  
  <p>Was the question clear? to understand my issue.</p>