Reading Csv file with chinese characters in php - php

I am reading a CSV file with Chinese characters,
and when i use print_r() it give me that type of array
Array ( [0] => PK!ȣ�4v�[Content_Types].xml ��(��T�n�0�W�?D�V��CUU]�-�L �IRP�h$.�����%�鮲�"�21J�"�{m�*�����H����z������f�����f�$ ) Array ( [0] => ORb^B�0�?)|��e\ɠ�Z��d����b2~�Bm [1] => %�;��*Y'�����**krE [2] => Tn��C2�Ear�>�T�b��4�T�4DÌqDl���?�t4�����*f�;+�#{�졗��F��io{S��mA�g�`�2k?Ly���&`Cwvݙ|��^z��v*u�Jw�}�\�Y�%����ACB$���qsk�MmQ6��-<���+ց�����_������ݥ㸋�G�|����g6 �����PK!�U0#�L�_rels/.rels ��(����N�0��H�C���nH���LH�!T�$����$#����Jc�����?[���iTb/Nú(A�3b{�jx��V�b"gi��aW��l_x���b���������#b4O��r��0Q�ahѓ�eܔ�=��P-<��j{�>�<���4Mox/�}b�N�#�;�v�Cf��ۨ�B�I�����"c�&�\O���8q"K��H��<ߊs#��.�h����<⧄�Md�a��T_��PK!�>����xl/_rels/workbook.xml.rels �(����J�0����nӮ""��E��j}��L��m2㟾���ۅe���f���2���k�&�WP%�&��w ) Array ( [0] => ޚ���[=� ) Array ( [0] => &$���W�4�K��H"�xR��㣔d�����NҨ9��ɨ�Aw(7ey/���O�� ) Array ( [0] => ��ނh�����m�| ) Array ( [0] => �}D�g"$�4��F�Y��.2#���5�9��鳔�Y]b��d��#��%�s�"�ݚ0�tB��)���[����ȓ�����PK!�ك�N"xl/workbook.xml�QAN�0�#�k��I�Z5����P�ce�Mcձ-�!��荓=;����ruj%�B�V���Js�|l^��8�gR+ [1] => ��V��Ͳ������� ) Array ( [0] => h�7J]�`��DT���m���3w �o%͒dF[&� ) Array ( [0] => � ]ע�']u-*?�X�̇�]#��rY���aƼ�6�}�#$s�����i��ǫ���c'dd�$Z��|��c�:�7��E=�M�l;c[���}!9�⺏�!���j'�o��9���������q�G~0|3�D �Ƙ��j�U~/��am1�up��.v��8 [1] => �hTLV�[<��l��������PK!���xl/sharedStrings.xml�Uێ�0}G� [2] => ���V [3] => J�*a�V�R)��ٵ'����d��A�'���nʶ��>�3ǚ��$�zhr�J��r6��B�*�_o�o(�Ȕ`�V�� Xz�>[���*���{E���2;�(ǔڴݧ�"�`���6ѫ��"j�T�p�+L��%���z��ח4��LcL�H�YaG[`��Z-z��Y�j�� j����k���p!�{�;�f5>��K֐�ƫY�=p_� [4] => �� w )�$�zŏ��A��e~CE��f`���4�� �5�q�"�o4O>e��7Z�/8k��`IQ�`&5�n���2:*c�C���� ȸ4�?�}Ua}Ft'�y Ȫ�F�ie�����8(/�G�#�G��r$ �ȡ`�:r��9����.9y89;�<���)��40��3P!�K���vY��;�]�5�%a������n�ﺱ����m7�3+�ד��s�}�������Ou�������PK!;m2K�B#xl/worksheets/_rels/sheet1.xml.rels�����0E��Cx{�օCS7"�U�b��ۗ���{�e���p��6��<�f� [1] => Ժ��ch��{�-�A�8�� -<�a�.��NNJ�ǐX��Q$��~�ٱ� ��>��I�y0���Ь�jm�_�/N�� [2] => �}W�:=RY��}�H9�E��bA�w��k}�m���� ��PK!�%��Sxl/theme/theme1.xml�YOo�6��w tom'�u�ر��M�n�i��XS�#�I}��úa���0l+��t�&[����HJ��K��ՇD"|���#u�ڃ��C"$�q۫]�z��>�8h{w��K� ) Array ( [0] => �c�xL�ޜH�����]ś*$A�>����J%����a��ACM��ʈ���J����&M�;��4B�e� t�Y�>c~4$��� ) Array ( [0] => &�^������ ) Array ( [0] => �L1�bma]���u��t���(gZ��[Wvr���2���u{���`�M� [1] => E���F��� [2] => ���2�n�Q�����%�[�N��Je�D �>֗��f}{����7����v��t�d��%|�J�Yw�2O��ڡ�~J=�L8�-�o|���(��<�4� �ժX��}.��#����'d�}��.�F�b�o\��C�\Ҽ��MT��0��z�����S�����ώ�t�����--g�.����~����?�~����xY����'���y92h!ы/����ɋ�>����%�m�GE��FD�[��t3�q%'#q��Sg�v � ) Array ( [0] => �9fe�q�wW#�(^��wd�b�h �a��8g.J pC�*Xx8��r�bV�`|Xƻ�cǵ�YU3J��ݐ8b�3+��(�������Q��u���K>Q�ELKM2�#'��vi~����vl�wu8+�z��HH�J���:�)��� ~��L��\�E\O*�t#G�1��l�m��~C�*u��G.R(:-�ys^D��i7�QR��8 [1] => b?�SQ���*��q7C�;��+�}��ݧ�;4pDZ��� �K(�N��h�wŘQ��6�㶷 [SYJ�(��p��»�g�>�X_�x���wu�{���\>k�]X���y�}�钣�M�26PsFnJ�'K� [2] => �}����䇦$�Ǵ�;�#`� �>�*�8���i"�LI%\������x�ӕ=6��������u=� r2f� ��3c�� ������(��:�jZ�3s��L�s��*��U��ܚЅ �]��M8�k�p6���������x�"]$C<&�����>�'e�b. vJ|��y�X����ɾ��8�Ȯ��]�7�R�/�=�� [3] => .&'��Q�k5��q��&p���(�K��a�ݐ�� �S��d��L17 jpSa����S!��� 3���5'+�Z�zQ ) Array ( [0] => �H )�7 �5)���k�dB|UtvaD�ξ�����p|�Fl&0�_�*�3�n'LE�/p���m���&]����8fI��r�S4�d7y��`� ) Array ( [0] => �n���ί�I�R���3U�~��c�nrF:_�*�P����}���-p�Tp�l�r��ۜ�4LZéO� ) Array ( [0] => �� ) Array ( [0] => !�P�L��B���]�$K ��*�++��6�5���v�ꦚ�e��NƟ��f�(�MN1ߜ��6����&3(��a��d��E [1] => �U�z�<�{���E�Uϲ���V���)�9�Z[��4^kd�5���!J���?��Q�3�qBo�C~���M����m<�.�vp�����IYӦ���Z�Y_p���=al-�Y�}Nc�͙���ŋ4vja��vl����'S�&�A�8�|�*~x������1%M0�g%����<���ҭ���PK!5�՗�J? xl/styles.xml�[[��F~���`Y�c��V�.]���m�lԾ0�_�1���;��� [2] => �b��fm�|�;�9g����E���O7A��λ�i�� �gK/ ) Array ( [0] => �}~٢�R�(���.�Hf.�~rfĦ�i#4$�l�"�A%�.�����F'IV���k�'�bZ�֫1Y�qq`�kdU�䤫��t]Do��&������ yw���M3۵�~��I�x�7h�M��#������ټ�c�i�^3�&\�V0uO��K�{�ɝ�m<�P��Ϧύ�d��5����O_ȲU�(����aX-l���2�� [1] => ���ʼnQ���X�X�p+�ݙ_�Ro߱XiT�I�`A [2] => VS�)J����N��\��*�#��;����q8m��t8l�r�i��K��A]�7m̦E2p�"Y�Y#�����p8tz��`���aF���/�f�132���{���uW6���A�3���r��4mӮ�۫M^h�*[�����L�i���#�W���o8��{U`�ɫM^e=��*�c���#�W�������C�^h���j����s�$]��\5z��K��&��_fع����f��Β [3] => K" [4] => o��^��V9��{b$z�hS���5��0i����s��Pe�V�N�i�����76 ���E����d��f$۞W\�!��s;_�$i� ) Array ( [0] => �)�`�f�V��(CBqD:򆡪��5��: ) Array ( [0] => #Tu�ԩ�\�%�v�o캃v��.��z#�xMĜshϳCj [1] => zv��MK�!�̍G�>lY���z�P���:�qS�q�ŧ�\�䍽����Q�zT���_(�����:��ni��ȍ�hZ��%��+� [2] => �R����A��2��:�?o�����&�ƮR��=����`G>뽘9��4��y�n����1>�>�H��5�#�a'e{\#{�Z�.Z�#Δ�7����Ġ>ŧI������( �`�J�"]9���ҕ" ) Array ( [0] => �2�� ])R�+G ) Array ( [0] => �Е" ) Array ( [0] => ���)zBW�9�ʑ���)PЕ!O�7N�-�m�7Q����k����>*-���[O����S�q�+�VJ�Iw����֩���1�]j����n�n3i����� [1] => `У�c�j�b�j<����Bl�o��m�V>�F�9�npw�1�X�mr ) Array ( [0] => �̱ [1] => �9���X#(�(c X0�X�c����PE ) Array ( [0] => [1] => �'r���0���m�U��S�G���He^"�#�m*_���HY_��ʗbq?R��X�\���HEY�B�]�U�ѡ�α������Q�UJ�*�D [2] => �G9Vm�X���X%�/���T�^����Q��b�u�~�m�U��ی*G���9 ) Array ( [0] => ��� %�(�kr�ۊQ��p���(�w��= ��f��m�T����o�Ż���Q���:�b/Kҽ��� ) Array ( [0] => NvzW�$�l$#X8U!�'^q�۳�Rq�#�a�� �������蜍�P��s9���I�C��V�s)�n��A��_ȑ#g $U���m�zU��S�R4�3=Pa�)"%�|p�X>��iD��!$j���k� fd y^w�*��K��i��&Z*<^��+�7E�o/�i�HS�M�шon��_��s!����#�~�]�Kof/՗c�b��! [1] => �_}�'����#=��YL�����K����PK!����<�xl/worksheets/sheet1.xml��[s�0��;�����ܤ��&��8�7d� F�����>Dz��$��#����U�EQ&2Y��e��"'�"d����)�b��L��(������F��R���2dK����R�xّ�ȴ2�Ŋ+}Y [2] => �2/��V��u�?�O2��0(l��y���>V"S�$�H���/�I^��0N�V��S�yȠ7�G���a��c"6ek�(�6����5�(�_��:i�>�w�w}��zt�M]�HY?R-�#��ŧ��Ӽ~7��^�ݭ�ow0���N [3] => ��#Uwrs*��R��w{s�G�Bn Io��y��7��V��.T;Y���Qw��jѧv��zX;jk��m���q[�6ik}�U3$#�H$�ڢG="�zB"!�DB����+ !#��D�J�#�;���=B P����� ����O#*{��T�>A��}� ) Array ( [0] => �OY���)+T�>e��ߧ�P� ) Array ( [0] => % ��P� ) Array ( [0] => e ��P� ) Array ( [0] => � ��P� ) Array ( [0] => � ���Շ��d������4�xg��;�+G���!{h��-c���l��-'fK�I�����Y�̖s���l�4[�̖k���l�5[�̖��ro�<�-�/�T�Of˳��b���-�<�E �"�`I��$X� [1] => R ��\�E0�"�`M��&X� [2] => � ��|�E#�"�`Ѫ�"���iY��#�qɋE��N��"��t��S4=J=� S}�Ϝ7��\m�����7�v|�̥T��U�΄��Y$���;���PO�^a��!+�q��v�����PK!�vA�� 'xl/printerSettings/printerSettings1.bin�a�a(f(e�c(g��)�#V1Pԃ!�A���!�Ke(b��%#�C �`F&�;.�����b)#��!� ��� ���Dc�d5q������|#'+�10��F���b�7�'$��9X��� 3T *ƯS1�ili ) Array ( [0] => &6 �|:z�A���� #��.tqd>(�#�D#���#���LL-H�d=�� Gln�Sd�·ɡ�&>4r����Ԁ� [1] => l`j��PK!&i�^EMdocProps/core.xml �(���]K�0���C�}��u:CۉʮV�Br���h�o�uu�^��ɓ�R [2] => v��>�yit�H��47B�M���e �G����w����%V�`��0���J�'��p� C ) Array ( [0] => t�$���^�R���~���[�C8�;/'�m͇ۤ}�_WOè���]q#�~? �aկr-A�v��B��5�7�b�I�Q� �U)w���������^�*K� [1] => N�qJj��삒���~5 ���?ƼNg4��3rb< ) Array ( [0] => ����P}��PK!Ie\o�docProps/app.xml �(��R�J1��Ò{�m����"=��Qbv��&Kf��~����nՓ9��{�yy���o����.�LLƩH�ې;���z�8� �񹩂�Lŭ��P�j���𘉒��I�����1Þ�"ĭ!n�F��p��m����鵄=��!�߂�W�5�_�<����5֊w.��N��jiM�Lׅ��< �L�¸�Z54k�R� �Oc*�w��.�Dc�3�xYK뛮�j��_C���PI&�îr���ғ���9��0pnq�|.&��'Cǝ��oo��7~�|g�rH��v��?=9���z�1��Z�&B����#�9�X�"���ȏ�߀�������t��Qr0S��7���PK-!ȣ�4v[Content_Types].xmlPK-!�U0#�L�_rels/.relsPK-!�>����pxl/_rels/workbook.xml.relsPK-!�ك�N"�xl/workbook.xmlPK-!��� ) Array ( [0] => xl/sharedStrings.xmlPK-!;m2K�B#\xl/worksheets/_rels/sheet1.xml.relsPK-!�%��S^ xl/theme/theme1.xmlPK-!5�՗�J? xl/styles.xmlPK-!����<� xl/worksheets/sheet1.xmlPK-!�vA�� '�xl/printerSettings/printerSettings1.binPK-!&i�^EM� docProps/core.xmlPK-!Ie\o�O#docProps/app.xmlPK&�% )
I encoded that CSV file with encode in UTF-8 without BOM.
For encoding, I just open csv file in notepad++ and then encode with encode in UTF-8 without BOM and then save it into CSV
Any kind of help will be appreciate.

I just spent half a day trying to figure this out and noticed this is still open; so for anyone looking for the answer I found changing the encoding type of my .csv files fixed it. To do this, I opened the file in excel, and saved to replace the file, this time selecting the UTF-8 CSV encoding option. I believe you can also change the file encoding type in apps such as Notepad++ if you don't have an office.
Hope this helps! Sorry if I missed anything, it's my first time posting on this site :D

Related

convert array text file into array in php

I have text file of array values
for example
[26-11-2018 04:07:26]: Array
(
[0] => api.flights_published_search
[1] => Array
(
[0] => Array
(
[ticket_type] => single
[departure_airport_id] => THR
[arrival_airport_id] => MHD
[departure_date] => 21/12/2018
[direct_flight_only] => 0
[adults] => 1
[children] => 1
[child_ages] => Array
(
[1] => 11
)
[infants] => 1
[cabin_class] => Y
)
)
)
[26-11-2018 04:07:27]: Array
(
[status] => 1
[pscId] => 0
[localInventory] => Array
(
[cal] => 0
[resp] => Array
(
)
)
[error] => Array
(
[status] =>
[error] => Error Code: 3037, Error: No availability on chosen flights.
)
)
I want to convert into as it is in array through php coding . so can anyone suggegst best way to convert this text to php array

get array name from multilevel array in php

how i can get WP_Widget_Archives from array,
This is my array:
$control = Array
(
[name] => Archives
[id] => archives-6
[callback] => Array
(
[0] => WP_Widget_Archives Object
(
[id_base] => archives
[name] => Archives
[widget_options] => Array
(
[classname] => widget_archive
[description] => A monthly archive of your site’s Posts.
)
[control_options] => Array
(
[id_base] => archives
)
[number] => 8
[id] => archives-8
[updated] =>
[option_name] => widget_archives
)
[1] => form_callback
)
[params] => Array
(
[0] => Array
(
[number] => 6
)
)
[width] => 250
[height] => 200
[id_base] => archives
)
i have try with this code
`echo '<pre>'; print_r(array_keys($control['callback'])); echo '</pre>';`
but I get result like this
Array
(
[0] => 0
[1] => 1
)
where I think the result will be like this
$result = Array
(
[0] => WP_Widget_Archives Object
[1] => form_callback
)
so i can write $result[0] for get WP_Widget_Archives, please help me and thank you for your help :)
Probably you misunderstood array_key function. It will give you keys of the array not value. In your case you require value which is an object 'WP_Widget_Archives', so you can directly use $control['callback'][0].

PHP - Re-arrange multi-array so that certain combinations have the same key(index)

I have an array, which looks like this:
Array
(
[sku_0017768] => Array
(
[0] => 0f359ce5bf6dc855f160c9b89b4aada0
)
[sku_0017766] => Array
(
[0] => ff5a47bd699bcb52944d0727a5b443b6
[1] => 0f359ce5bf6dc855f160c9b89b4aada0
)
[sku_0017723] => Array
(
[3] => a3c83832b4089d83d164b3cac596fc7e
)
[sku_0017767] => Array
(
[0] => fb91d14d405be52ce989acd2918ea1a0
)
[sku_8402350] => Array
(
[0] => a3c83832b4089d83d164b3cac596fc7e
[1] => fb91d14d405be52ce989acd2918ea1a0
[2] => ff5a47bd699bcb52944d0727a5b443b6
[3] => d14afce16e477663ebe51fdd65cd5010
)
[sku_8402200] => Array
(
[0] => d14afce16e477663ebe51fdd65cd5010
)
)
Now, this array represents a list of SKU's with one or more 'combination codes'. So, in this example 'sku_0017768' matches product sku_0017766 because they share the same combination code.
sku_8402350 has multiple combination as you can see.
What I need to have now is a new array, where the index(key) of the combination code needs to be same among the other products within the combination.
Output should look like this:
Array
(
[sku_0017768] => Array
(
[0] => 0f359ce5bf6dc855f160c9b89b4aada0
)
[sku_0017766] => Array
(
[0] => 0f359ce5bf6dc855f160c9b89b4aada0
[1] => ff5a47bd699bcb52944d0727a5b443b6
)
[sku_0017723] => Array
(
[0] => a3c83832b4089d83d164b3cac596fc7e
)
[sku_0017767] => Array
(
[0] => fb91d14d405be52ce989acd2918ea1a0
)
[sku_8402350] => Array
(
[0] => fb91d14d405be52ce989acd2918ea1a0
[1] => ff5a47bd699bcb52944d0727a5b443b6
[2] => d14afce16e477663ebe51fdd65cd5010
[3] => a3c83832b4089d83d164b3cac596fc7e
)
[sku_8402200] => Array
(
[2] => d14afce16e477663ebe51fdd65cd5010
)
)
The difficulty I have is that when a key is already in use, the key of the other products within the combination should increase (with 1) as well, until there is an empty key which the combination can use.
Can anybody help me pointing me in the right direction? Feel free to ask if anything is not clear.

Select every first array value in associative array

I dynamically create this associative file array through a PHP script, and now I am wondering how do I select all values inside the root array?
I'll explain here in code.
This is the array that is currently getting generated everytime:
Array
(
[HTML] => Array
(
[0] => Index.php
)
[Javascript] => Array
(
[0] => Javascript.js
[1] => Jquery.js
)
[0] => New Text Document.txt
[Scripts] => Array
(
[0] => Get_Server_files.Script.php
)
[Style] => Array
(
[0] => General.css
[1] => Menu.css
[2] => Style.css
)
[images] => Array
(
[WelcomeImages] => Array
(
[0] => WelcomeImage0.png
[1] => WelcomeImage1.png
[2] => WelcomeImage2.png
[3] => WelcomeImage3.png
[4] => WelcomeImage4.png
[5] => WelcomeImage5.png
[6] => WelcomeImage6.png
)
[0] => bg.jpg
)
)
From here, how do I select every first value? As in selecting
HTML
Javascript
Scripts
Style
Images.
And not anything that is inside these arrays.
I have searched but everytime it's not quite what I would like.
You can use array_keys() to get the names and then use array_filter() to remove the 0 values:
$names = array_filter(array_keys($data));
print_r($names);
Output:
Array
(
[0] => HTML
[1] => Javascript
[3] => Scripts
[4] => Style
[5] => images
)
Demo.
Use array_keys()
$keys = array_keys($array);

PHP Change Array Structure / Format

I have an array at present that looks like this:
Array
(
[0] => Array
(
[language] => English
)
[1] => Array
(
[language] => Arabic
)
[2] => Array
(
[language] => Bengali
)
)
What I'd like to do is change it so it looks like this:
Array
(
[language] => Array
(
[0] => English
[1] => Arabic
[2] => Bengali
)
)
I also have an array that looks like this:
Array
(
[id] => 3
[name] => lethalMango
[joined] => 2010-01-01 00:00:00
)
And I'd like to change it to:
Array
(
[user] => Array
(
[id] => 3
[name] => lethalMango
[joined] => 2010-01-01 00:00:00
)
)
I've tried a number of methods without much success but I'm sure there is an more efficient way.
FIRST :
$result = array();
foreach($array as $value){
$result['language'][]= $value['language']
}
SECOND :
$result['user'] = $array;
Second
$result = array('user'=>$array);

Categories