explode mysql string for $wpdb->insert - php

I'm trying to explode this string, so it can fit "$wpdb->insert" function in wordpress.
this is the string to insert. The file contains about 42k strings like this:
(601, 'STANDARD', 'Adjuntas', '', 'Colinas Del Gigante, Jard De Adjuntas, Urb San Joaquin', 'PR', 'Adjuntas', 'America/Puerto_Rico', '787,939', '18.16', '-66.72', 'NA', 'US', 0, 0, ''),
this is the code
if ( file_exists(realpath(dirname(__FILE__)).'/install/usa_zip_codes.sql')){
$filecontent = explode("\n",file_get_contents( realpath(dirname(__FILE__)).'/install/usa_zip_codes.sql'));
foreach( $filecontent as $row){
$array = array();
$array = explode(", ", trim(preg_replace("/[()]/","",$row),","));
$wpdb->insert(
$wpmyplugin_table['yp_usa_zip_codes'],
array(
'zip' => $array[0],
'type' => trim($array[1],"'"),
'primary_city' => trim($array[2],"'"),
'acceptable_cities' => trim($array[3],"'"),
'unacceptable_cities' => trim($array[4],"'"),
'state' => trim($array[5],"'"),
....
but when i have strings like 'Colinas Del Gigante, Jard De Adjuntas, Urb San Joaquin', it will also split it to array elements. I've tried to explode by explode(", '", but this part , 0, 0, '' wont be split correctly. How do you deal with these things?

Have a look at str_getcsv. You should be able to convert
(601, 'STANDARD', 'Adjuntas', '', 'Colinas Del Gigante, Jard De Adjuntas, Urb San Joaquin', 'PR', 'Adjuntas', 'America/Puerto_Rico', '787,939', '18.16', '-66.72', 'NA', 'US', 0, 0, ''),
Into:
601, 'STANDARD', 'Adjuntas', '', 'Colinas Del Gigante, Jard De Adjuntas, Urb San Joaquin', 'PR', 'Adjuntas', 'America/Puerto_Rico', '787,939', '18.16', '-66.72', 'NA', 'US', 0, 0, ''
str_getcsv can then be used to turn the above string into an array. This will ignore commas inside of values.

Related

How to remove currency abbreviations from right side of strings?

I have a sample array like this:
[
"BTCUSD",
"DASHBTC",
"DOGEUSD",
"LTCBTC",
"LTCUSD",
"SCBTC",
"STEEMBTC",
"WAVESBTC",
"SNGLSBTC",
"1STBTC",
"DASHUSD",
"BQXETH",
"PTOYETH",
"XAURETH",
"BTCUSDT"
]
How to get just one currency for every string? I can't use explode because there isn't a single/static delimiter. I can't use substr() or strpos() because the substrings vary.
So how to split it?
Update
This is my expected output
[
"BTC",
"DASH",
"DOGE",
"LTC",
"LTC",
"SC",
"STEEM",
"WAVES",
"SNGLS",
"1ST",
"DASH",
"BQX",
"PTOY",
"XAUR",
"BTC"
]
You need to have an array to your expected currencies and then filter against it.
Here is a quick and dirty solution: https://3v4l.org/6mMbN or with recursive function call: https://3v4l.org/mhjBD
<?php
$currencies = [
'USD',
'BTC',
'DASH',
'LTC',
'SC',
'STEEM',
'WAVES',
'SNGLS',
'1ST',
'BQX',
'ETH',
'PTOY',
'XAUR',
];
$input = [
"BTCUSD",
"DASHBTC",
"DOGEUSD",
"LTCBTC",
"LTCUSD",
"SCBTC",
"STEEMBTC",
"WAVESBTC",
"SNGLSBTC",
"1STBTC",
"DASHUSD",
"BQXETH",
"PTOYETH",
"XAURETH",
"BTCUSDT",
];
$output=[];
foreach($input as $doubleCurrency){
foreach($currencies as $currency){
$pattern = '/^'.$currency. '/';
preg_match($pattern, $doubleCurrency, $matches);
if(array_key_exists(0, $matches)){
$output[]=$matches[0];
}
}
}
var_dump($output);
You are always trimming the right side of the string, just use preg_replace() with an end of string anchor. No lookup array is necessary. It doesn't get much easier that this:
Code: (Demo)
$input=[
"BTCUSD",
"DASHBTC",
"DOGEUSD",
"LTCBTC",
"LTCUSD",
"SCBTC",
"STEEMBTC",
"WAVESBTC",
"SNGLSBTC",
"1STBTC",
"DASHUSD",
"BQXETH",
"PTOYETH",
"XAURETH",
"BTCUSDT"
];
var_export(preg_replace('/USDT$|USD$|ETH$|BTC$/','',$input));
Output:
array (
0 => 'BTC',
1 => 'DASH',
2 => 'DOGE',
3 => 'LTC',
4 => 'LTC',
5 => 'SC',
6 => 'STEEM',
7 => 'WAVES',
8 => 'SNGLS',
9 => '1ST',
10 => 'DASH',
11 => 'BQX',
12 => 'PTOY',
13 => 'XAUR',
14 => 'BTC',
)
(The pattern can be condensed if you don't mind the syntax. /USDT?$|ETH$|BTC$/ is a little faster.)
Here is an answer that is similar to Edwin's but is probably faster.
I use str_replace to create a space in-between the currencies then I loop the new array and remove anything after the first space.
Example:
'STEEMBTC' becomes STEEM BTC '.
Then substr it to: 'STEEM'.
Probably quicker code as it loops less and does not use regex.
$currencies = [
'USD',
'BTC',
'DASH',
'LTC',
'SC',
'STEEM',
'WAVES',
'SNGLS',
'1ST',
'BQX',
'ETH',
'PTOY',
'XAUR',
'DOGE'
];
$repl = [
'USD ',
'BTC ',
'DASH ',
'LTC ',
'SC ',
'STEEM ',
'WAVES ',
'SNGLS ',
'1ST ',
'BQX ',
'ETH ',
'PTOY ',
'XAUR ',
'DOGE '
];
$input = [
"BTCUSD",
"DASHBTC",
"DOGEUSD",
"LTCBTC",
"LTCUSD",
"SCBTC",
"STEEMBTC",
"WAVESBTC",
"SNGLSBTC",
"1STBTC",
"DASHUSD",
"BQXETH",
"PTOYETH",
"XAURETH",
"BTCUSDT",
];
$new = str_replace($currencies, $repl, $input);
Foreach($new as &$item){
$item = substr($item, 0, strpos($item, " "));
}
Var_dump($new);
https://3v4l.org/QDMjS

preg_replace with associative array

I have some like this:
$fabrics = array (
'B' => 'BAWEŁNA',
'P' => 'POLIESTER',
'S' => 'SPANDEX',
'E' => 'ELASTAN',
'PO' => 'POLIAMID',
'EL' => 'ELASTAN',
'A' => 'AKRYL',
'AN' => 'ANGORA',
'NY' => 'NYLON',
'W' => 'WEŁNA',
'WO' => 'WEŁNA OWCZA',
'POL' => 'POLIWINYL',
'PVC' => 'PCV',
'SZJ' => 'SZTUCZNY JEDWAB',
'SK' => 'SKÓRA NATURALNA',
'POP' => 'POLIPROPYLEN'
);
$textiles = array( 'B 100%', 'B 80%, P 20%', 'NY 70%, EL 30%', 'B 75%, S 20%', 'SZJ 80%, E 20%');
// rand textilies
$textile = $textiles[array_rand($textiles)];
echo $textile.'</br>';
echo preg_replace(array_keys($fabrics), $fabrics, $textile);
And i want use preg_replace to change a key in full name. But it's not work corectly.:/ Can you help?
Your array keys aren't regular expressions, they're just ordinary strings. You can use strtr() for this.
echo strtr($textile, $fabrics);
With two arguments, the second argument is an associative array of from => to.

Convert charcters from any languages to english characters

I'm searching for a function that can transform or convert any characters (from all languages) to English characters.
I saw mb_convert_encoding, iconv('UTF-8', 'ASCII//TRANSLIT', $str) , ....
I probably miss something...
Example : I want to go from '后杨庄' to 'hou yang zhuang'
but iconv echo nothing ;( and mb_convert echo 后杨庄.
Is someone knows how to better use mb_convert or iconv ?
or is there a better PHP function that can achieve this ?
Thanks to answer
you mean romanize (right?), because translation is one thing, and convert encoding another, and romanization a third one
Korean Syllable PHP or JavaScript Romanizer (or any other alternative?)
I finally found Transliterator plugin for PHP
And with combination with iconv I can remove all accents from all languages
$transliterator = Transliterator::create( "Any-Latin; [:Punctuation:] Remove; NFD; NFC;" );
$jStringAccentsRemoved = $transliterator->transliterate($jStringToRemoveAccents);
$jStringAccentsRemoved = iconv('UTF-8', 'us-ascii//TRANSLIT', $jStringAccentsRemoved);
* IMPROVED CODE (but PECL intl and PECL translit required) *
$tranliterare_Parameters = "Any-Latin; NFD; NFC; NFKD; NFKC; ";
$transliterator = Transliterator::create( $tranliterare_Parameters );
$stringToClean = $transliterator->transliterate($stringToClean);
$stringToClean = transliterate( $stringToClean, array( 'han_transliterate', 'diacritical_remove' ), 'utf-8', 'utf-8');
$stringToClean = preg_replace('/\p{Mn}/u', '', Normalizer::normalize($stringToClean, Normalizer::FORM_KD));
// this extra portion is from http://d3s.mff.cuni.cz/~holub/sw/phpaccents/
$unwanted_array = array(
'œ' => 'oe' , 'æ' => 'ae' , 'đ' => 'd' , 'ð' => 'd' , 'ø' => 'o' , 'ł' => 'l' , 'ß' => 'ss' ,
'Œ' => 'OE' , 'Æ' => 'AE' , 'Đ' => 'D' , 'Ð' => 'D' , 'Ø' => 'O' , 'Ł' => 'L' ,
'Ə' => 'E', 'ə' => 'e', 'Ǝ' => 'E', 'ə' => 'e','ı' => 'i','I' => 'i',
'`' => '' , '?' => '' , ' ' => ' ' , '"' => '' , "'" => '' ,
'À'=>'A','Á'=>'A','Â'=>'A','Ã'=>'A','Ä'=>'A','Å'=>'A','Ç'=>'C','È'=>'E',
'É'=>'E','Ê'=>'E','Ë'=>'E','Ì'=>'I','Í'=>'I','Î'=>'I','Ï'=>'I','Ñ'=>'N',
'Ò'=>'O','Ó'=>'O','Ô'=>'O','Õ'=>'O','Ö'=>'O','Ø'=>'O','Ù'=>'U','Ú'=>'U',
'Û'=>'U','Ü'=>'U','Ý'=>'Y','à'=>'a','á'=>'a','â'=>'a','ã'=>'a','ä'=>'a',
'å'=>'a','ç'=>'c','è'=>'e','é'=>'e','ê'=>'e','ë'=>'e','ì'=>'i','í'=>'i',
'î'=>'i','ï'=>'i','ñ'=>'n','ò'=>'o','ó'=>'o','ô'=>'o','õ'=>'o','ö'=>'o',
'ø'=>'o','ù'=>'u','ú'=>'u','û'=>'u','ü'=>'u','ý'=>'y','ÿ'=>'y','Ā'=>'A',
'ā'=>'a','Ă'=>'A','ă'=>'a','Ą'=>'A','ą'=>'a','Ć'=>'C','ć'=>'c','Ĉ'=>'C',
'ĉ'=>'c','Ċ'=>'C','ċ'=>'c','Č'=>'C','č'=>'c','Ď'=>'D','ď'=>'d','Đ'=>'D',
'đ'=>'d','Ē'=>'E','ē'=>'e','Ĕ'=>'E','ĕ'=>'e','Ė'=>'E','ė'=>'e','Ę'=>'E',
'ę'=>'e','Ě'=>'E','ě'=>'e','Ĝ'=>'G','ĝ'=>'g','Ğ'=>'G','ğ'=>'g','Ġ'=>'G',
'ġ'=>'g','Ģ'=>'G','ģ'=>'g','Ĥ'=>'H','ĥ'=>'h','Ħ'=>'H','ħ'=>'h','Ĩ'=>'I',
'ĩ'=>'i','Ī'=>'I','ī'=>'i','Ĭ'=>'I','ĭ'=>'i','Į'=>'I','į'=>'i','İ'=>'I',
'ı'=>'i','Ĵ'=>'J','ĵ'=>'j','Ķ'=>'K','ķ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>'e','Ề'=>'E','ề'=>'e','Ể'=>'E','ể'=>'e','Ễ'=>'E',
'ễ'=>'e','Ệ'=>'E','ệ'=>'e','Ỉ'=>'I','ỉ'=>'i','Ị'=>'I','ị'=>'i','Ọ'=>'O',
'ọ'=>'o','Ỏ'=>'O','ỏ'=>'o','Ố'=>'O','ố'=>'o','Ồ'=>'O','ồ'=>'o','Ổ'=>'O',
'ổ'=>'o','Ỗ'=>'O','ỗ'=>'o','Ộ'=>'O','ộ'=>'o','Ớ'=>'O','ớ'=>'o','Ờ'=>'O',
'ờ'=>'o','Ở'=>'O','ở'=>'o','Ỡ'=>'O','ỡ'=>'o','Ợ'=>'O','ợ'=>'o','Ụ'=>'U',
'ụ'=>'u','Ủ'=>'U','ủ'=>'u','Ứ'=>'U','ứ'=>'u','Ừ'=>'U','ừ'=>'u','Ử'=>'U',
'ử'=>'u','Ữ'=>'U','ữ'=>'u','Ự'=>'U','ự'=>'u','Ỳ'=>'Y','ỳ'=>'y','Ỵ'=>'Y',
'ỵ'=>'y','Ỷ'=>'Y','ỷ'=>'y','Ỹ'=>'Y','ỹ'=>'y','Ỿ'=>'Y','ỿ'=>'y','ⁱ'=>'i',
'ⁿ'=>'n','ₐ'=>'a','ₑ'=>'e','ₒ'=>'o','ₓ'=>'x','⒜'=>'a','⒝'=>'b','⒞'=>'c',
'⒟'=>'d','⒠'=>'e','⒡'=>'f','⒢'=>'g','⒣'=>'h','⒤'=>'i','⒥'=>'j','⒦'=>'k',
'⒧'=>'l','⒨'=>'m','⒩'=>'n','⒪'=>'o','⒫'=>'p','⒬'=>'q','⒭'=>'r','⒮'=>'s',
'⒯'=>'t','⒰'=>'u','⒱'=>'v','⒲'=>'w','⒳'=>'x','⒴'=>'y','⒵'=>'z','Ⓐ'=>'A',
'Ⓑ'=>'B','Ⓒ'=>'C','Ⓓ'=>'D','Ⓔ'=>'E','Ⓕ'=>'F','Ⓖ'=>'G','Ⓗ'=>'H','Ⓘ'=>'I',
'Ⓙ'=>'J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'=>'V','ꝟ'=>'v','A'=>'A','B'=>'B','C'=>'C','D'=>'D','E'=>'E','F'=>'F',
'G'=>'G','H'=>'H','I'=>'I','J'=>'J','K'=>'K','L'=>'L','M'=>'M','N'=>'N',
'O'=>'O','P'=>'P','Q'=>'Q','R'=>'R','S'=>'S','T'=>'T','U'=>'U','V'=>'V',
'W'=>'W','X'=>'X','Y'=>'Y','Z'=>'Z','a'=>'a','b'=>'b','c'=>'c','d'=>'d',
'e'=>'e','f'=>'f','g'=>'g','h'=>'h','i'=>'i','j'=>'j','k'=>'k','l'=>'l',
'm'=>'m','n'=>'n','o'=>'o','p'=>'p','q'=>'q','r'=>'r','s'=>'s','t'=>'t',
'u'=>'u','v'=>'v','w'=>'w','x'=>'x','y'=>'y','z'=>'z'
);
$stringToClean = strtr( $stringToClean , $unwanted_array );
The result :
FROM
后杨庄 • องค์การโทรศัพท์ร่อนพิบูลย àéç öî-ïüùç ËÀÌ --- ÀØėÿᾜὨζὅБю ---
Ⱥⱥ Ƀƀ Ȼȼ Đđ Ɇɇ Ǥǥ Ħħ Ɨɨ Ɉɉ Ꝁꝁ Łł Øø Ᵽᵽ Ɍɍ Ŧŧ Ʉʉ Ɏɏ Ƶƶ
TO
hou yang zhuang • xngkhkar thorsaphth rxnphibuly aec oi-iuuc EAi --- AOeyEiOzhoBu ---\
Aa Bb Cc Dd Ee GG Hh Ii Jj Kk Ll Oo Pp Rr Tt Uu Yy Zz

PHP: Linking an array value with a variable

I have an array that stores names of countries (keys) and age expectancy (values).
$countries = array(
'Costa Rica' => 78, 'Puerto Rico' => 78, 'Colombia' => 73,
'Nicaragua' => 73, 'El Salvador' => 72, 'Peru' => 71,
'Argentina' => 75, 'Uruguay' => 76, 'Ecuador' => 75,
'Mexico' => 76, 'Venezuela' => 73, 'Brasil' => 72,
);
An html form creates a new variable ($country) with a name that corresponds to one countries listed above.
For example: "Costa Rica"
How can I return a variable with the number (age expectancy) that matches the name of the country in the $country variable?
Take for example:
Costa Rica = 78
$ageExpectancy = 78;
Thanks, I hope to be concise.
<?php
$country = $_POST['country']; // assuming post method and form element named 'country'
$ageExpectancy = $countries[$country];
?>

php table of values

I have a table of values like this:
http://www.conversiontable.org/clothingsizeconversiontable.html
and I want to declare these values in a php class and then manipulate them easily.
In your opinion, what is the best way to do such thing?
You can build an array indexed by country name and then by size number:
$country_sizes = array(
'United States' => array(6, 8, 10, 12, 14, 16, 18),
...
)
But in order to avoid mistakes and make the code more readable, I would assign a label to each size type. Then I would build an array indexed by size type first, and then by country:
$sizes = array(
'S' => array(
'United States' => 6,
'United Kingdom' => 28,
...
),
'M' => array(
'United States' => 8,
'United Kingdom' => 30,
...
),
...
);
This second way is more tedious to build, but seems more natural to me (what's the S size in U.K.?). Anyway, it's your choice according to your needs ;)
something like:
$sizes = array(
'United States' => array(6, 8, 10, 12, 14, 16, 18),
'United Kingdom' => array (28, 30, 32, 34, 36, 38, 40)
);
echo('United states first size: ' . $sizes['United States'][0]);

Categories