Reputation: 3
I'm trying to pull data in CSV format for a server, process and store in a MySQL database:
When I insert into my database, the text is "Atila%27s+Goonies" I want it to be "Atila's Goonies"
I have been reading through all the text encoding topics, but I think I'm missing a very simple function.
My requirement is to have this text and store in the database as a properly formatted (or encoded) string, so I can query later and display online. Database column is collated as "utf8_unicode_ci". I'm not sure if it's relevant because if I want to display on the browser, I cannot get to the correct format either. thanks.
Any help would be appreciated.
My code below:
if (($handle = fopen("alliances.txt", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
$alliance_id = $data[0];
$alliance_name = $data[1];
$alliance_points = $data[2];
$alliance_villages = $data[3];
$alliance_members = $data[4];
$alliance_rank = $data[5];
$sql_ia = "insert into alliances (alliance_id,alliance_name, alliance_villages,alliance_members,alliance_rank,timestamp)
values (:alliance_id,:alliance_name, :alliance_villages,:alliance_members,:alliance_rank,:timestamp)";
$st_ia = $DBcon->prepare($sql_ia);
$st_ia->bindParam(':alliance_rank', $alliance_rank,PDO::PARAM_INT);
$st_ia->bindParam(':alliance_id', $alliance_id,PDO::PARAM_INT);
$st_ia->bindParam(':alliance_name',$alliance_name,PDO::PARAM_STR);
$st_ia->bindParam(':alliance_members',$alliance_members,PDO::PARAM_INT);
$st_ia->bindParam(':alliance_villages',$alliance_villages,PDO::PARAM_INT);
$st_ia->bindParam(':timestamp',$timestamp,PDO::PARAM_INT);
$author_name = $ag_row[$agency];
$st_ia->execute();
}
fclose($handle);
}
Upvotes: 0
Views: 26
Reputation: 2704
Try this.
<?php
$encoded = 'Atila%27s+Goonies';
// Your string is URL encoded. Use urldecode() to decode.
$decoded = urldecode($encoded);
var_dump($decoded); // string(15) "Atila's Goonies"
Upvotes: 1