Note that there are some explanatory texts on larger screens.

plurals
  1. POUse foreach() to loop through object and change values
    primarykey
    data
    text
    <p>I've got a problem looping trough an object ( stdObject ) and altering a value.</p> <p>What happens is: </p> <ul> <li>a query result comes in the function.</li> <li>It fetches the object to an 'array'</li> <li>After that I need to decode the content inside the object with html_entity_decode() to convert <code>&amp;amp;</code> etc. to readable characters... </li> </ul> <p>Thats what is going wrong. I don't know how to put the converted string back into the object.</p> <p>Here is the code of this function.</p> <pre> function jsonRequestHandlerUTF8($query) { $id = "0"; $message = errorHandler($id); $a_result = array(); if (mysql_num_rows($query) == 0) { //Empty sql query $id = '1'; $a_result = jSONErrorObject($id); } else { //No error occurred $a_result['ExceptionId'] = $id; $a_result['ExceptionMessage'] = $message; $a_result['Items'] = null; while ($my_result = mysql_fetch_object($query)) { $a_result['Items'][] = $my_result; } $test = $a_result['Items']; foreach ($test as $v1) { foreach ($v1 as $v2) { $v2 = html_entity_decode($v2, ENT_QUOTES, "utf-8") . "\n"; // Here should be code to get the $v2 inside the object again..... } } } $a_result = json_encode($a_result); return $a_result; } </pre> <p>$a_result['Items'] looks like this:</p> <pre> Array ( [0] => stdClass Object ( [idziekmeldingen] => 1 [meldingID] => 13190 [title] => Ziekmelding: Alex [published] => 2011-05-09 [updated] => 2011-05-09 [content] => Per 9-05-2011 heeft Alex zich ziek gemeld. [location] => AP [institute] => CMI [lastCron] => 2011-05-11 11:32:54 ) [1] => stdClass Object ( [idziekmeldingen] => 2 [meldingID] => 12933 [title] => Ziekmelding: Rimmert [published] => 2011-04-26 [updated] => 2011-04-26 [content] => Per 26-04-2011 heeft Rimmer zich ziek gemeld.Met vriendelijke groet,Luci&euml;nne Plomp [location] => AP [institute] => CMI [lastCron] => 2011-05-11 11:32:54 ) ) </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload