gpt4 book ai didi

javascript - 将 Jvectormap jQuery 文件导入 MySql 的最佳实践

转载 作者:行者123 更新时间:2023-11-29 03:39:27 27 4
gpt4 key购买 nike

我正在尝试将 SVG 数据放入 MySQL 数据库中,而无需复制和粘贴超过 200 行。有没有办法将以下内容导入 MySQL 数据库:

"LR": {
"path": "M401.37,273.67l-0.32,0.01l-2.48,-1.15l-2.24,-1.89l-2.14,-1.38l-1.47,-1.42l0.44,-0.59l0.05,-0.13l0.12,-0.65l1.07,-1.3l1.08,-1.09l0.52,-0.07l0.43,-0.18l0.84,1.24l-0.15,0.89l0.07,0.25l0.49,0.54l0.22,0.1l0.71,0.01l0.27,-0.16l0.42,-0.83l0.19,0.02l-0.06,0.52l0.23,1.12l-0.5,1.03l0.06,0.35l0.73,0.69l0.14,0.08l0.71,0.15l0.92,0.91l0.06,0.76l-0.17,0.22l-0.06,0.15l-0.17,1.8Z",
"name": "Liberia",
"continent": "africa"
},

非常感谢任何帮助。

最佳答案

这应该可以解决问题:)

<?php

$db ='
"BD": {
"path": "M652.71,228.85l-0.04,1.38l-0.46,-0.21l-0.42,0.3l0.05,0.65l-0.17,-1.37l-0.48,-1.26l-1.08,-1.6l-0.23,-0.13l-2.31,-0.11l-0.31,0.36l0.21,0.98l-0.6,1.11l-0.8,-0.4l-0.37,0.09l-0.23,0.3l-0.54,-0.21l-0.78,-0.19l-0.38,-2.04l-0.83,-1.89l0.4,-1.5l-0.16,-0.35l-1.24,-0.57l0.36,-0.62l1.5,-0.95l0.02,-0.49l-1.62,-1.26l0.64,-1.31l1.7,1.0l0.12,0.04l0.96,0.11l0.19,1.62l0.25,0.26l2.38,0.37l2.32,-0.04l1.06,0.33l-0.92,1.79l-0.97,0.13l-0.23,0.16l-0.77,1.51l0.05,0.35l1.37,1.37l0.5,-0.14l0.35,-1.46l0.24,-0.0l1.24,3.92Z",
"name": "Bangladesh"
},
"BE": {
"path": "M429.28,143.95l1.76,0.25l0.13,-0.01l2.16,-0.64l1.46,1.34l1.26,0.71l-0.23,1.8l-0.44,0.08l-0.24,0.25l-0.2,1.36l-1.8,-1.22l-0.23,-0.05l-1.14,0.23l-1.62,-1.43l-1.15,-1.31l-0.21,-0.1l-0.95,-0.04l-0.21,-0.68l1.66,-0.54Z",
"name": "Belgium"
},
"BF": {
"path": "M413.48,260.21l-1.22,-0.46l-0.13,-0.02l-1.17,0.1l-0.15,0.06l-0.73,0.53l-0.87,-0.41l-0.39,-0.75l-0.13,-0.13l-0.98,-0.48l-0.14,-1.2l0.63,-0.99l0.05,-0.18l-0.05,-0.73l1.9,-2.01l0.08,-0.14l0.35,-1.65l0.49,-0.44l1.05,0.3l0.21,-0.02l1.05,-0.52l0.13,-0.13l0.3,-0.58l1.87,-1.1l0.11,-0.1l0.43,-0.72l2.23,-1.01l1.21,-0.32l0.51,0.4l0.19,0.06l1.25,-0.01l-0.14,0.89l0.01,0.13l0.34,1.16l0.06,0.11l1.35,1.59l0.07,1.13l0.24,0.28l2.64,0.53l-0.05,1.39l-0.42,0.59l-1.11,0.21l-0.22,0.17l-0.46,0.99l-0.69,0.23l-2.12,-0.05l-1.14,-0.2l-0.19,0.03l-0.72,0.36l-1.07,-0.17l-4.35,0.12l-0.29,0.29l-0.06,1.44l0.25,1.45Z",
"name": "Burkina Faso",
"continent": "africa"
}
';

$dbeach = explode("}", $db);

print_r($dbeach);

function get_string($string, $start, $end){
$string = " ".$string;
$pos = strpos($string,$start);
if ($pos == 0) return "";
$pos += strlen($start);
$len = strpos($string,$end,$pos) - $pos;
return substr($string,$pos,$len);
}


$con=mysqli_connect("host","username","pass","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


foreach ($dbeach as $value) {

$countrycode = get_string($value, '"', '": {');
$path = get_string($value, '"path": "', '",');
$name = get_string($value, '"name": "', '",');
$continent = get_string($value, '"continent": "', '"');

mysqli_query($con,"INSERT INTO countries (countrycode, path, name, continent)
VALUES ('$countrycode', '$path', '$name', '$continent')");
}
mysqli_close($con);

?>

关于javascript - 将 Jvectormap jQuery 文件导入 MySql 的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16232946/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com