Adjust cell data in CSV file, PHP - php

I am writing header in CSV by using this
fputcsv($fp, $columns);
It writes the header in CSV as follow
AED AFN ALL AMD ANG AOA ARS AUD AWG AZN BAM BBD BDT BGN BHD BIF BMD BND BOB BRL BSD BTC BTN BWP BYR BZD CAD CDF CHF CLF CLP CNY COP CRC CUC CUP CVE CZK DJF DKK DOP DZD EEK EGP ERN ETB EUR FJD FKP GBP GEL GGP GHS GIP GMD GNF GTQ GYD HKD HNL HRK HTG HUF IDR ILS IMP INR IQD IRR ISK JEP JMD JOD JPY KES KGS KHR KMF KPW KRW KWD KYD KZT LAK LBP LKR LRD LSL LTL LVL LYD MAD MDL MGA MKD MMK MNT MOP MRO MUR MVR MWK MXN MYR MZN NAD NGN NIO NOK NPR NZD OMR PAB PEN PGK PHP PKR PLN PYG QAR RON RSD RUB RWF SAR SBD SCR SDG SEK SGD SHP SLL SOS SRD STD SVC SYP SZL THB TJS TMT TND TOP TRY TTD TWD TZS UAH UGX USD UYU UZS VEF VND VUV WST XAF XAG XAU XCD XDR XOF XPF YER ZAR ZMK ZMW ZWL
above data is in $columns array.
Using above data there is 168 columns.
Now i am using for loop to fetch data
$num_records=count($columns);
for($z=1;$z<$num_records;$z++){
$rowData=fetchData($columns[$z] ,$columns[$z],1);
fputcsv($fp, $rowData);
}
Here is fetchData function
function fetchData($from,$to,$amount){
$access_key = 'MYKEY';
$endpoint = 'live';
// initialize CURL:
if($from=="GNF"){
$url='http://apilayer.net/api/'.$endpoint.'?access_key='.$access_key.'&from='.$from.'&to='.$to.'&amount='.$amount.'&source='.$from."";
$ch = curl_init($url);
//echo $url;exit;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// get the (still encoded) JSON data:
$json = curl_exec($ch);
curl_close($ch);
// Decode JSON response:
$conversionResult = json_decode($json, true);
$tmpArray=$conversionResult['quotes'];
if($from=="")
$from="USD";
array_unshift($tmpArray, $from);
}
return $tmpArray;
}
For GNF its returning 166 data. means less then header.
Now my problem is because for GNF array has 166 conversion, And we have 168 columns.
So its not showing as per header in CSV.
Please tell me how i can fix this so it will show data as per header.
Here is the generated CSV. You can see its not showing data correctly.
https://www.dropbox.com/s/oo0a6ni4xkebat9/currency.csv?dl=0&s=sl

You're missing 2 columns because your FOR loop for($z=1; $z < $num_records; $z++) ignores the element [0] and the last element [167]. This should fix:
$num_records=count($columns);
for($z=0; $z <= $num_records; $z++){
$rowData=fetchData($columns[$z] ,$columns[$z],1);
fputcsv($fp, $rowData);
}

Related

PHP NumberFormatter: Decimal Digits bug - SOLVED

I'm new to using NumberFormatter (PHP) and right at the beginning I encountered a strange behavior that I consider a bug.
I have searched for a solution but have not found one.
I want to present prices according to customer conventions (correct decimal and thousands separators and correct currency marking), and I always want to present prices without the decimal part.
When I use the setAttribute(NumberFormatter::FRACTION_DIGITS, 0) and/or setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 0) settings, this only works for the currency intended for payments in that country. For prices in other currencies, it ignores the number of decimal places parameter.
Am I doing something wrong? How to force the given setting for all outputs?
Example code:
<?php
$val = 1234567.891234567890000;
$lngs = array("de_DE", "de_CH", "fr_CH", "nl_NL", "en_US", "en_GB", "cs_CZ");
$crncs = array("EUR", "CZK", "USD", "GBP", "CHF");
echo "<table border='1' style='width:auto;'>";
foreach($lngs as $lng) {
echo "<tr><th colspan='3' style='text-align: center;'>$lng</th>";
foreach ($crncs as $currency) {
$fmt = new NumberFormatter($lng, NumberFormatter::CURRENCY );
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 0); // this will be ignored everywhere except in a direct currency-language match
echo "<tr style='text-align: right;'><td>" . $currency . "</td><td>" . $fmt->formatCurrency($val, $currency) . "</td><td>" . $fmt->formatCurrency(-1 * $val, $currency) . "</td></tr>";
}
}
echo "</table>";
working example here
my output:
de_DE
EUR 1.234.568 € -1.234.568 €
CZK 1.234.567,89 CZK -1.234.567,89 CZK
USD 1.234.567,89 $ -1.234.567,89 $
GBP 1.234.567,89 £ -1.234.567,89 £
CHF 1.234.567,90 CHF -1.234.567,90 CHF
de_CH
EUR € 1'234'567.89 €-1'234'567.89
CZK CZK 1'234'567.89 CZK-1'234'567.89
USD $ 1'234'567.89 $-1'234'567.89
GBP £ 1'234'567.89 £-1'234'567.89
CHF CHF 1'234'568 CHF-1'234'568
fr_CH
EUR € 1'234'567.89 €-1'234'567.89
CZK CZK 1'234'567.89 CZK-1'234'567.89
USD $US 1'234'567.89 $US-1'234'567.89
GBP £UK 1'234'567.89 £UK-1'234'567.89
CHF CHF 1'234'568 CHF-1'234'568
nl_NL
EUR € 1.234.568 € 1.234.568-
CZK CZK 1.234.567,89 CZK 1.234.567,89-
USD US$ 1.234.567,89 US$ 1.234.567,89-
GBP £ 1.234.567,89 £ 1.234.567,89-
CHF CHF 1.234.567,90 CHF 1.234.567,90-
en_US
EUR €1,234,567.89 (€1,234,567.89)
CZK CZK1,234,567.89 (CZK1,234,567.89)
USD $1,234,568 ($1,234,568)
GBP £1,234,567.89 (£1,234,567.89)
CHF CHF1,234,567.90 (CHF1,234,567.90)
en_GB
EUR €1,234,567.89 -€1,234,567.89
CZK CZK1,234,567.89 -CZK1,234,567.89
USD $1,234,567.89 -$1,234,567.89
GBP £1,234,568 -£1,234,568
CHF CHF1,234,567.90 -CHF1,234,567.90
cs_CZ
EUR 1 234 567,89 € -1 234 567,89 €
CZK 1 234 568 Kč -1 234 568 Kč
USD 1 234 567,89 US$ -1 234 567,89 US$
GBP 1 234 567,89 £ -1 234 567,89 £
CHF 1 234 567,90 CHF -1 234 567,90 CHF
SOLUTION:
After further searching and elaboring I FOUND THE SOLUTION.
Before setting the number of decimal places, you still need to explicitly specify the currency:
$fmt->setTextAttribute(NumberFormatter::CURRENCY_CODE, $currency);
The function code is then:
<?php
$val = 1234567.891234567890000;
$lngs = array("de_DE", "de_CH", "fr_CH", "nl_NL", "en_US", "en_GB", "cs_CZ");
$crncs = array("EUR", "CZK", "USD", "GBP", "CHF");
echo "<table border='1' style='width:auto;'>";
foreach($lngs as $lng) {
echo "<tr><th colspan='3' style='text-align: center;'>$lng</th>";
foreach ($crncs as $currency) {
$fmt = new NumberFormatter($lng, NumberFormatter::CURRENCY );
// new line of code that solves the problem
$fmt->setTextAttribute(NumberFormatter::CURRENCY_CODE, $currency);
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
echo "<tr style='text-align: right;'><td>" . $currency . "</td><td>" . $fmt->formatCurrency($val, $currency) . "</td><td>" . $fmt->formatCurrency(-1 * $val, $currency) . "</td></tr>";
}
}
echo "</table>";

RegEx for extracting mobile numbers with a specific format

I have an sms text from mysql. The text contains 5 types of text. Firstly a 11 mobile number ( 01***********) format. And two amounts of money, One transaction ID with 10 digit uppercase letters and number and a date-time. I need to extract each of the text and store it in different variables.
Example text: Cash In Tk 500.00 from 01789788881 successful. Fee Tk 0.00. Balance Tk 4,145.08. TrxID 6E63D2OS4R at 06/05/2019 20:24.
So far i tried to extract the phone number
$sms_text = $result['sms_text'];
preg_match('/\b\d{3}\s*-\s*\d{3}\s*-\s*\d{4}\b/', $sms_text, $sms_from);
echo $sms_from;
echo $cash_in_amount;
echo $fee;
echo $ trx_id;
echo $trx_time;
How do I solve this problem?
You can use this regex, and extract the three values from group1, group2 and group3 and of course I can assume here that your SMS text would be in same format.
from\s+(\d+).*([a-zA-Z0-9]{10})\s+at\s+(.*)
Regex Demo 1
PHP Code Demo
$sms = 'Cash In Tk 500.00 from 01789788881 successful. Fee Tk 0.00. Balance Tk 4,145.08. TrxID 6E63D2OS4R at 06/05/2019 20:24';
preg_match_all('/from\s+(\d+).*([a-zA-Z0-9]{10})\s+at\s+(.*)/', $sms, $matches);
print('Mobile Number: '.$matches[1][0]."\n");
print('Transaction Id: '.$matches[2][0]."\n");
print('Date Time: '.$matches[3][0]."\n");
Output,
Mobile Number: 01789788881
Transaction Id: 6E63D2OS4R
Date Time: 06/05/2019 20:24
Edit:
For getting Cash In Tk 500.00 and Fee Tk 0.00 you can use following regex,
(\S+)\s+from\s+(\d+).*Fee\s+Tk\s+(\S+)\..*([a-zA-Z0-9]{10})\s+at\s+(.*)
Regex Demo 2
Updated PHP Demo
$sms = 'Cash In Tk 500.00 from 01789788881 successful. Fee Tk 0.00. Balance Tk 4,145.08. TrxID 6E63D2OS4R at 06/05/2019 20:24';
preg_match_all('/(\S+)\s+from\s+(\d+).*Fee\s+Tk\s+(\S+)\..*([a-zA-Z0-9]{10})\s+at\s+(.*)/', $sms, $matches);
print('Cash In Tk: '.$matches[1][0]."\n");
print('Mobile Number: '.$matches[2][0]."\n");
print('Fee Tk: '.$matches[3][0]."\n");
print('Transaction Id: '.$matches[4][0]."\n");
print('Date Time: '.$matches[5][0]."\n");
Prints,
Cash In Tk: 500.00
Mobile Number: 01789788881
Fee Tk: 0.00
Transaction Id: 6E63D2OS4R
Date Time: 06/05/2019 20:24

Running array through dictionary with repeated values

So, i have two files, first is a text file, and the second is a encryption of the first file:
textfile:
cryptool (starting example for the cryptool version family 1.x)
cryptool is a comprehensive free educational program about
cryptography and cryptanalysis offering extensive online help and many
visualizations.
this is a text file, created in order to help you to make your first
steps with cryptool.
1) as a first step it is recommended you read the included online
help, this will provide a useful oversight of all available functions
within this application. the starting page of the online help can be
accessed via the menu "help -> starting page" at the top right of the
screen or using the search keyword "starting page" within the index of
the online help. press f1 to start the online help everywhere in
cryptool.
2) a possible next step would be to encrypt a file with the caesar
algorithm. this can be done via the menu "crypt/decrypt -> symmetric
(classic)".
3) there are several examples (tutorials) provided within the online
help which provide an easy way to gain an understanding of cryptology.
these examples can be found via the menu "help -> scenarios
(tutorials)".
4) you can also develop your knowledge by:
- navigating through the menus. you can press f1 at any selected menu item to get further information.
- reading the included readme file (see the menu "help -> readme").
- viewing the included colorful presentation (this presentation can be found on several ways: e.g. in the "help" menu of this application, or
via the "documentation" section found at the "starting" page of the
online help).
- viewing the webpage www.cryptool.org.
july 2010 the cryptool team
encrypted file:
ncjaezzw (delcetyr pilxawp qzc esp ncjaezzw gpcdtzy qlxtwj 1.i)
ncjaezzw td l nzxacpspydtgp qcpp pofnletzylw aczrclx lmzfe
ncjaezrclasj lyo ncjaelylwjdtd zqqpctyr piepydtgp zywtyp spwa lyo xlyj
gtdflwtkletzyd.
estd td l epie qtwp, ncplepo ty zcopc ez spwa jzf ez xlvp jzfc qtcde
depad htes ncjaezzw.
1) ld l qtcde depa te td cpnzxxpyopo jzf cplo esp tynwfopo zywtyp
spwa, estd htww aczgtop l fdpqfw zgpcdtrse zq lww lgltwlmwp qfynetzyd
htesty estd laawtnletzy. esp delcetyr alrp zq esp zywtyp spwa nly mp
lnnpddpo gtl esp xpyf "spwa -> delcetyr alrp" le esp eza ctrse zq esp
dncppy zc fdtyr esp dplcns vpjhzco "delcetyr alrp" htesty esp tyopi zq
esp zywtyp spwa. acpdd q1 ez delce esp zywtyp spwa pgpcjhspcp ty
ncjaezzw.
2) l azddtmwp ypie depa hzfwo mp ez pyncjae l qtwp htes esp nlpdlc
lwrzctesx. estd nly mp ozyp gtl esp xpyf "ncjae/opncjae -> djxxpectn
(nwlddtn)".
3) espcp lcp dpgpclw pilxawpd (efezctlwd) aczgtopo htesty esp zywtyp
spwa hstns aczgtop ly pldj hlj ez rlty ly fyopcdelyotyr zq ncjaezwzrj.
espdp pilxawpd nly mp qzfyo gtl esp xpyf "spwa -> dnpylctzd
(efezctlwd)".
4) jzf nly lwdz opgpwza jzfc vyzhwporp mj:
- ylgtrletyr esczfrs esp xpyfd. jzf nly acpdd q1 le lyj dpwpnepo xpyf tepx ez rpe qfcespc tyqzcxletzy.
- cplotyr esp tynwfopo cploxp qtwp (dpp esp xpyf "spwa -> cploxp").
- gtphtyr esp tynwfopo nzwzcqfw acpdpyeletzy (estd acpdpyeletzy nly mp qzfyo zy dpgpclw hljd: p.r. ty esp "spwa" xpyf zq estd laawtnletzy, zc
gtl esp "oznfxpyeletzy" dpnetzy qzfyo le esp "delcetyr" alrp zq esp
zywtyp spwa).
- gtphtyr esp hpmalrp hhh.ncjaezzw.zcr.
ufwj 2010 esp ncjaezzw eplx
Im counting letter ocurrences in both files, creating a dictionary, so i can go back into the encrypted file and change most of the letters to the right ones, some wont be changed but i'll do it manually later.
Problem is, i think the fact that some letters have the same number of ocurrences, its changing the same letter more than one time.
Heres my code so far, the problem is surelly in the foreach loops but im not managing to fix it. Maybe i can use flags but i have no idea how to do this in a foreach cycle.
//gets string from both text files
$reference = file_get_contents('reference_file.txt', true);
$encrypted = file_get_contents('encrypted_file.txt', true);
//Uses regex to take away all the characters wich are not letters
$azreference = preg_replace("/[^a-z]+/", "", $reference);
$azencrypted = preg_replace("/[^a-z]+/", "", $encrypted);
//Counts number of letter ocurrences and makes a string: "Char => Ocurrences"
$refarray1 = array_count_values(str_split($azreference, '1'));
$refarray2 = array_count_values(str_split($azencrypted, '1'));
foreach ($refarray1 as $key => $val) {
foreach ($refarray2 as $key2 => $val2) {
if ($val == $val2){
$encrypted = str_replace($key2, $key, $encrypted); // (replaces $key2 for $key)
}
}
}
print_r($encrypted);
The output string is, wich is kinda wrong xD:
jjdebdda (wbdjbbdj ebdbeae zdj bwe jjdebdda jejwbdd zdbbad 1.b)
jjdebdda bw d jdbejewedwbje zjee edzjdbbddda ejdjjdb dbdzb
jjdebdjjdewd ddd jjdebdddadwbw dzzejbdj ebbedwbje ddabde weae ddd bddd
jbwzdabzdbbddw. bwbw bw d bebb zbae, jjedbed bd djdej bd weae ddz bd
bdje ddzj zbjwb wbeew wbbw jjdebdda. 1) dw d zbjwb wbee bb bw
jejdbbedded ddz jedd bwe bdjazded ddabde weae, bwbw wbaa ejdjbde d
zwezza djejwbjwb dz daa djdbadbae zzdjbbddw wbbwbd bwbw deeabjdbbdd.
bwe wbdjbbdj edje dz bwe ddabde weae jdd be djjewwed jbd bwe bedz
"weae -> wbdjbbdj edje" db bwe bde jbjwb dz bwe wjjeed dj zwbdj bwe
wedjjw jedwdjd "wbdjbbdj edje" wbbwbd bwe bddeb dz bwe ddabde weae.
ejeww z1 bd wbdjb bwe ddabde weae ejejdwweje bd jjdebdda. 2) d
edwwbbae debb wbee wdzad be bd edjjdeb d zbae wbbw bwe jdewdj
dajdjbbwb. bwbw jdd be ddde jbd bwe bedz "jjdeb/dejjdeb -> wdbbebjbj
(jadwwbj)". 3) bweje dje wejejda ebdbeaew (bzbdjbdaw) ejdjbded wbbwbd
bwe ddabde weae wwbjw ejdjbde dd edwd wdd bd jdbd dd zddejwbdddbdj dz
jjdebdadjd. bwewe ebdbeaew jdd be zdzdd jbd bwe bedz "weae ->
wjeddjbdw (bzbdjbdaw)". 4) ddz jdd dawd dejeade ddzj jddwaedje bd: -
ddjbjdbbdj bwjdzjw bwe bedzw. ddz jdd ejeww z1 db ddd weaejbed bedz
bbeb bd jeb zzjbwej bdzdjbdbbdd. - jeddbdj bwe bdjazded jeddbe zbae
(wee bwe bedz "weae -> jeddbe"). - jbewbdj bwe bdjazded jdadjzza
ejewedbdbbdd (bwbw ejewedbdbbdd jdd be zdzdd dd wejejda wddw: e.j. bd
bwe "weae" bedz dz bwbw deeabjdbbdd, dj jbd bwe "ddjzbedbdbbdd"
wejbbdd zdzdd db bwe "wbdjbbdj" edje dz bwe ddabde weae). - jbewbdj
bwe webedje www.jjdebdda.djj. zzad 2010 bwe jjdebdda bedb
some wont be changed but i'll do it manually later.
So, if you are ready to fix smth later manually, and in order to avoid the problem of re-replacing (meaning replace all the vocabulary in "one hop") you can use the php function strtr (http://php.net/manual/en/function.strtr.php) and change your code just a bit, like the following:
//gets string from both text files
$reference = file_get_contents('reference_file.txt', true);
$encrypted = file_get_contents('encrypted_file.txt', true);
//Uses regex to take away all the characters wich are not letters
$azreference = preg_replace("/[^a-z]+/", "", $reference);
$azencrypted = preg_replace("/[^a-z]+/", "", $encrypted);
//Counts number of letter ocurrences and makes a string: "Char => Ocurrences"
$refarray1 = array_count_values(str_split($azreference, '1'));
$refarray2 = array_count_values(str_split($azencrypted, '1'));
$replacement = array();
foreach ($refarray1 as $key => $val) {
foreach ($refarray2 as $key2 => $val2) {
if ($val == $val2){
$replacement[$key2] = $key;
}
}
}
$encrypted = strtr($encrypted, $replacement);
print_r($encrypted);
The output will be:
cryptnnl (stnrting exnmple fnr the cryptnnl versinn fnmily 1.x)
cryptnnl is n cnmprehensive free educntinnnl prngrnm nbnut cryptngrnphy nnd cryptnnnlysis nffering extensive nnline help nnd mnny visunlijntinns.
this is n text file, crented in nrder tn help ynu tn mnke ynur first steps with cryptnnl.
1) ns n first step it is recnmmended ynu rend the included nnline help, this will prnvide n useful nversight nf nll nvnilnble functinns within this npplicntinn. the stnrting pnge nf the nnline help cnn be nccessed vin the menu "help -> stnrting pnge" nt the tnp right nf the screen nr using the senrch keywnrd "stnrting pnge" within the index nf the nnline help. press f1 tn stnrt the nnline help everywhere in cryptnnl.
2) n pnssible next step wnuld be tn encrypt n file with the cnesnr nlgnrithm. this cnn be dnne vin the menu "crypt/decrypt -> symmetric (clnssic)".
3) there nre severnl exnmples (tutnrinls) prnvided within the nnline help which prnvide nn ensy wny tn gnin nn understnnding nf cryptnlngy. these exnmples cnn be fnund vin the menu "help -> scennrins (tutnrinls)".
4) ynu cnn nlsn develnp ynur knnwledge by: - nnvignting thrnugh the menus. ynu cnn press f1 nt nny selected menu item tn get further infnrmntinn. - rending the included rendme file (see the menu "help -> rendme"). - viewing the included cnlnrful presentntinn (this presentntinn cnn be fnund nn severnl wnys: e.g. in the "help" menu nf this npplicntinn, nr vin the "dncumentntinn" sectinn fnund nt the "stnrting" pnge nf the nnline help). - viewing the webpnge www.cryptnnl.nrg.
july 2010 the cryptnnl tenmi
which is a bit better than "jjdebdda" :) , but, as you expected, still has some collisions.

cURL font encoding-error

I want to get contents via cURL from this page.
Here is my code:
$url = $_GET["url"];
$url = str_replace(" ", "%20", $url);
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true);
$jsonData = curl_exec($curlSession);
curl_close($curlSession);
if (strpos($url, "toomva.com") >= 0) {
$jsonData = str_replace("toomva.com", "http://av.bsquochoai.ga ⇔ ", $jsonData);
}
if (strpos($url, "Toomva -") >= 0){
$jsonData = str_replace("toomva.com", "http://av.bsquochoai.ga ⇔ ", $jsonData);
}
echo($jsonData);
Here you can find a live demo.
My problem is that the returned text is not as I expect. It has a lot of �����:
��1� � �0�0�:�0�0�:�2�4�,�4�0�0� �-�-�>� �0�0�:�0�0�:�3�3�,�1�4�0� �
�M��i� �k�h�i� �a�n�h� �t�r���n�g� �t�h��y� �k�h�u���n� �m��t� �e�m�,�
�t�h�� �g�i�a�n� �n���y� �n�h�� �c�h��t� �t�a�n� �b�i��n� � �
Can you please help me with this?
Here are the first few bytes of the file you're trying to access:
$ curl -s 'http://toomva.com/Data/subtitle/Duncan%20James%20ft.%20Keedie%20-%20I%20Believe%20My%20Heart.Vie_Syned.srt' | xxd | head
0000000: fffe 3100 0d00 0a00 3000 3000 3a00 3000 ..1.....0.0.:.0.
0000010: 3000 3a00 3200 3400 2c00 3400 3000 3000 0.:.2.4.,.4.0.0.
0000020: 2000 2d00 2d00 3e00 2000 3000 3000 3a00 .-.-.>. .0.0.:.
0000030: 3000 3000 3a00 3300 3300 2c00 3100 3400 0.0.:.3.3.,.1.4.
0000040: 3000 0d00 0a00 4d00 d71e 6900 2000 6b00 0.....M...i. .k.
0000050: 6800 6900 2000 6100 6e00 6800 2000 7400 h.i. .a.n.h. .t.
0000060: 7200 f400 6e00 6700 2000 7400 6800 a51e r...n.g. .t.h...
0000070: 7900 2000 6b00 6800 7500 f400 6e00 2000 y. .k.h.u...n. .
0000080: 6d00 b71e 7400 2000 6500 6d00 2c00 2000 m...t. .e.m.,. .
0000090: 7400 6800 bf1e 2000 6700 6900 6100 6e00 t.h... .g.i.a.n.
It starts with 0xff 0xfe, which is the byte order mark for UTF-16 Little Endian. This information should really be provided in the file's HTTP headers, but apparently not in this case.
You can use PHP's mb_convert_encoding() function to change the file's content into whatever character set you're using for your website. For example, this will convert it into utf-8:
$src = file_get_contents('http://toomva.com/Data/subtitle/Duncan%20James%20ft.%20Keedie%20-%20I%20Believe%20My%20Heart.Vie_Syned.srt');
$utf8src = mb_convert_encoding($src,'UTF-8','UTF-16LE');
header('Content-Type: text/plain; charset=utf-8');
die($utf8src);
However, the file doesn't contain JSON data. Here are the first few lines:
1
00:00:24,400 --> 00:00:33,140
Mỗi khi anh trông thấy khuôn mặt em, thế gian này như chợt tan biến
2
00:00:33,140 --> 00:00:42,700
Tất cả đều phơi bày trong một ánh nhìn thoáng qua
use utf8_encode when you echo your jsonDate :
echo(utf8_encode($jsonData));

Create a Inner Join to create proper output

I am trying to get my data to look like the output below. I have a SQL with a Inner Join to
connect two tables so they will output the data so it looks like the below. I am not sure how to do this could somebody give me a example
This is what the output looks like now
First American
2014-03-17 Blackwell Vancouver 115
First American
2014-04-21 Kurth Vancouver 85
Title Source
2014-01-04 Kurth Vancouver 85
Title Source
2014-03-11 Kurth Vancouver 85
Title Source
2014-03-17 Kurth Vancouver 85
This is what I would like it to look like
First American
2014-03-17 Blackwell Vancouver 115
2014-04-21 Kurth Vancouver 85
Title Source
2014-01-04 Kurth Vancouver 85
2014-03-11 Kurth Vancouver 85
2014-03-17 Kurth Vancouver 85
$result = $db->query("SELECT customers.name,signings.pid,signings.done,signings.signstart,
signings.lname,signings.ordern, signings.city,signings.samount,signings.prtamount,
signings.faxamount FROM customers Inner Join signings On signings.custid = customers.custid
WHERE signings.pid = 6 AND signings.done = 1 GROUP BY customers.name, signings.pid,
signings.done,signings.signstart");
foreach($result as $key => $income) {
echo $income['name'];
echo '<br>';
$total = $income['samount'] + $income['prtamount'] + $income['faxamount'];
echo $income['signstart'] . ' ' .$income['lname']. ' ' .$income['city'] . ' ' .$total;
echo '<br>';
}
You can modify your PHP like this:
$current=null;
foreach($result as $key => $income) {
if($current!=$income['name']){
echo $income['name'];
$current = $income['name'];
}
//other stuff
}
Hope this solves it!

Categories