php function fgetcsv not work for line have \"" - php

I have data in phpmyadmin, example: (first row is header)
||from||to||messages||
||john||andy||meeting now||
||dony||sherly||Place in \"Jakarta\" , Indonesia, 15412
when I export to csv via phpmyadmin version 3.5.6, I get this csv file:
"from","to","messages"
"john","andy","meeting now"
"from","to","Place in \""Jakarta\"" , Indonesia, 15412"
if I use this code
<?php
// code start
$file = fopen($path, 'r');
while (($line = fgetcsv($file)) !== FALSE) {
print_r($line);
}
fclose($file);
// code end
?>
I hope get this
//output start
Array
(
[0] => from
[1] => to
[2] => messages
)
Array
(
[0] => john
[1] => andy
[2] => meeting now
)
Array
(
[0] => dony
[1] => sherly
[2] => Place in \"Jakarta\" , Indonesia, 15412
)
//output end
but instead I get
//output start
Array
(
[0] => from
[1] => to
[2] => messages
)
Array
(
[0] => john
[1] => andy
[2] => meeting now
)
Array
(
[0] => from
[1] => to
[2] => Place in \"Jakarta\""
[3] => Indonesia
[4] => 15412"
)
//output end
anyone can help this error?

You have double double quotes.
"from","to","Place in \""Jakarta\"" , Indonesia, 15412"
should be
"from","to","Place in \"Jakarta\" , Indonesia, 15412"

Related

PHP Get values from nested array

I am new to PHP and Arrays, I am trying to get the values from an array. But no matter how I'm trying to do it, I can't get the value. What am I doing wrong?
The Array:
Array ( [playerinfo] => Array ( [rank] => Godfather [cash] => € 8,520,530 [weapon] => M-16 (29000) [health] => Array ( [width] => 100 [color] => green ) [wealth] => Too rich to be true [protection] => Bulletproof Humvee [plf] => Huge [plane] => Concorde [crew] => None [pbf] => Large [ship] => None ) [character] => Array ( [crime] => Array ( [0] => 120 [1] => 69 ) [gta] => Array ( [0] => 400 [1] => 70 ) [drugs] => Array ( [0] => 120 [1] => 2528 ) [airport] => Array ( [0] => 2700 [1] => 2529 ) [oc] => Array ( [0] => 86400 [1] => 1442364 ) [tr] => Array ( [0] => 10800 [1] => 1640016011 ) [plf] => Array ( [0] => 7200 [1] => 6712 ) [kill] => Array ( [0] => 3600 [1] => 1640019611 ) ) )
The way I tried to get the info:
$AccData = json_decode($MobinfoString, true);
echo $AccData['playerinfo']['rank'].'<br/>';
echo $AccData['playerinfo']['cash'].'<br/>';
foreach ($AccData as $playerinfo) {
echo $playerinfo['playerinfo']['rank'].'<br/>';
echo $playerinfo['character']['gta'].'<br/>';
}
EDIT:
The json string
{"playerinfo":{"rank":"Boss","cash":"€ 5,923,712","weapon":"M-16 (4500)","health":{"width":"100","color":"green"},"wealth":"Too rich to be true","protection":"Bulletproof Humvee","plf":"Huge","plane":"Concorde","crew":"None","pbf":"Large","ship":"None"},"character":{"crime":[120,122],"gta":[400,369],"drugs":[120,2582],"airport":[2700,2582],"oc":[86400,1640020450],"tr":[10800,1640016850],"plf":[7200,3935],"kill":[3600,1640020450]}}
Anyone knows how to do this ? For example I need the Concorde from plane in a variable and the time values from gta in a variable. And some more from this string.
So your first Part is okay and you rank you can just display like the first part as well
$AccData = json_decode($MobinfoString, true);
echo $AccData['playerinfo']['rank'].'<br/>';
echo $AccData['playerinfo']['cash'].'<br/>';
echo $AccData['playerinfo']['rank'].'<br/>';
echo $AccData['playerinfo']['plane'].'<br/>';
echo $AccData['character']['gta'][0].'<br/>';
but the character is on the same level as playerinfo so you need to access it from AccData. also gta is an array like health, so you have to specify which value you want to show, the first so 0 or second which is 1

PHP Array delete an entire array by one element value

So this is how my Array ($dataArray) looks oks like:
Array
(
[0] => Array
(
[0] => Date
[1] => Time
[2] => Duration
[3] => Info
[4] => Client
)
[1] => Array
(
[0] => 2021-12-01
[1] => 10:45:43
[2] => 237
[3] => Some text from
[4] => Client 1
)
[2] => Array
(
[0] => 2021-12-01
[1] => 11:29:13
[2] => 77
[3] => Nothing important
[4] => Client 2
)
[3] => Array
(
[0] => 2021-12-01
[1] => 11:53:03
[2] => 44
[3] => anonymous
[4] => Client 1
)
I need to Loop trough it to search the Client Names, and if i find the matching name in the Element 4 then delete the entire Array.
$ExportKDname = "Client 1"
foreach($dataArray as $key => $sub_array) {
if($sub_array[4] == $ExportKDname) {
unset($dataArray[$key]);
break;
}
}
print_r($dataArray);
But with this code none of the arrays will be deleted. And I just can not find the right way to do it.
The Final array what I need to look like if we find the "Client 1" in the array would be like this:
Array
(
[0] => Array
(
[0] => Date
[1] => Time
[2] => Duration
[3] => Info
[4] => Client
)
[1] => Array
(
[0] => 2021-12-01
[1] => 11:29:13
[2] => 77
[3] => Nothing important
[4] => Client 2
)
In the if condition you are saying "if u match with $sub_arr[4] == $ExportKDname unset it and stop the loop". the machine doing that. when it matched first time it removes and stoping. If u wanna delete all match do not write break; let it continue. So delete or make it comment break; line.
You can array_filter your variable and check if value is in_array.
With PHP 7.4+ syntax it should look like this:
$result = array_filter($dataArray, fn ($innerArray) => !in_array('Client 1', $innerArray));

php json encode not encoding array

i have php array like (( print_r($fdata); ))
Array
(
[status] => YES
[data] => Array
(
[0] => Array
(
[0] => Array
(
[0] => Need
[1] => Am need
)
)
[1] => Array
(
[0] => Array
(
[0] => 0
[1] => No deductibles and no copayments.
)
[1] => Array
(
[0] => 1
[1] => No lifetime limit—policy won't terminate based on number or dollar amount of claims paid.
)
)
[2] => Array
(
[0] => Array
(
[0] => Volvo
[1] => 22
[2] => 18
)
[1] => Array
(
[0] => Volvo
[1] => 22
[2] => 18
)
)
[3] => Array
(
[0] => Array
(
[0] => Volvo
[1] => 22
[2] => 18
)
[1] => Array
(
[0] => Volvo
[1] => 22
[2] => 18
)
)
)
)
i want to encode it to json , but when i pass it to "json_encode" function it print blank result !
about my php code
i have declared few php array in which i load data from database
$fdata = array(); // final data to process
$product = array(); // product info
$adv_arr = array(); // advantages
$benefits_arr = array(); // benefits
$limits_arr = array(); // limits
$terms_arr = array(); // terms
after loading to arrays , i push them to one another array like
$ffdata = array();
array_push($ffdata , $product ,$adv_arr,$benefits_arr,$terms_arr);
and then it end i try to encode but no result
$fdata['status'] = "YES";
$fdata['data'] = $ffdata;
echo json_encode($fdata);
am trying to produce json data result like :: http://s1.postimg.org/efvvx74xr/C29_CA6_EA8_CAA946_E44076_CA72_B98502932_BA2_A6_DE4517_FB.jpg
sample data :: http://www.datafilehost.com/d/58c5d154
If json_encode() encounters an error when encoding a data set, it returns false, which will not echo.
In order to determine if the operation was erroneous, you can use json_last_error() and json_last_error_msg() to determine what went wrong.
For example:
$json = json_encode($data);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new RuntimeException(json_last_error_msg());
}
This should provide some more meaningful information if something goes wrong.
At this point, if you are getting a WSOD instead of any output then you might have a different problem; e.g: a fatal or parse error. In this case you should ensure that error reporting is enabled while developing (and, crucially, ensure it's disabled in your production environment!).
Generally, the easiest way to do this is to add the following to the top of your script:
<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
Hope this helps :)

Reading Csv file with chinese characters in 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

What is the regex for the text between quotes?

Ok, I have tried looking at other answers, but couldn't get mine solved. So here is the code:
{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}
I need to get every second value in the quotes (as the "name" values are constant). I actually worked out that I need to get text between :" and " but i can't manage to write a regex for that.
EDIT: I'm doing preg_match_all in php. And its between :" and ", not " and " as someone else edited.
Why on earth would you attempt to parse JSON with regular expressions? PHP already parses JSON properly, with built-in functionality.
Code:
<?php
$input = '{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}';
print_r(json_decode($input, true));
?>
Output:
Array
(
[chg] => -0.71
[vol] => 40700
[time] => 11.08.2011 12:29:09
[high] => 1.417
[low] => 1.360
[last] => 1.400
[pcl] => 1.410
[turnover] => 56,560.25
)
Live demo.
You may need to escape characters or add a forward slash to the front or back depending on your language. But it's basically:
:"([^"].*?)"
or
/:"([^"].*?)"/
I've test this in groovy as below and it works.
import java.util.regex.*;
String test='{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}'
// Create a pattern to match breaks
Pattern p = Pattern.compile(':"([^"]*)"');
// Split input with the pattern
// Run some matches
Matcher m = p.matcher(test);
while (m.find())
System.out.println("Found comment: "+m.group().replace('"','').replace(":",""));
Output was:
Found comment: -0.71
Found comment: 40700
Found comment: 11.08.2011 12:29:09
Found comment: 1.417
Found comment: 1.360
Found comment: 1.400
Found comment: 1.410
Found comment: 56,560.25
PHP Example
<?php
$subject = '{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}';
$pattern = '/(?<=:")[^"]*/';
preg_match_all($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?>
Output is:
Array ( [0] => Array ( [0] => Array ( [0] => -0.71 [1] => 8 ) [1] => Array ( [0] => 40700 [1] => 22 ) [2] => Array ( [0] => 11.08.2011 12:29:09 [1] => 37 ) [3] => Array ( [0] => 1.417 [1] => 66 ) [4] => Array ( [0] => 1.360 [1] => 80 ) [5] => Array ( [0] => 1.400 [1] => 95 ) [6] => Array ( [0] => 1.410 [1] => 109 ) [7] => Array ( [0] => 56,560.25 [1] => 128 ) ) )

Categories