Array replace doesn’t work properly or I’m missing something.
I want to replace any text which is equal to ‘An Error Occured while reading’ with ‘Reading has stopped after fatal error in you XML file but when I use PHP code below the value against key 0 gets updated which is wrong!
Any idea?
Thanks
Original state:
Array
(
[0] => Element 'item', attribute 'isd': The attribute 'isd' is not allowed.
[1] => Element 'item', attribute 'avai0lable': The attribute 'avai0lable' is not allowed.
[2] => Unimplemented block at ..\xmlschemas.c:28274
[3] => An Error Occured while reading
)
PHP code:
$errors = array_unique($errors);
$key = array_search('An Error Occured while reading', $errors);
$errors[$key] = 'Reading has stopped after fatal error in you XML file';
echo '<pre>'; print_r($errors); echo '</pre>';
Faulty result:
Array
(
[0] => Reading has stopped after fatal error in you XML file
[1] => Element 'item', attribute 'avai0lable': The attribute 'avai0lable' is not allowed.
[2] => Unimplemented block at ..\xmlschemas.c:28274
[3] => Reading has stopped after fatal error in you XML file
)
Correct code is: