【问题标题】:Convert a string to array in PHP在 PHP 中将字符串转换为数组
【发布时间】:2015-12-02 21:52:37
【问题描述】:

我使用 PDO 对数据库执行 postgresql 查询,然后以如下形式返回响应字符串:

POINT(23.7336253085595 38.0002872112492)

如何获取这些字符串的编号并将它们存储到不同的变量中?

这是我发送查询问题的代码:

include 'postgreConnect.php';



$maxGid = 1084;
for ($rowPostGis=1; $rowPostGis<=$maxGid;$rowPostGis++){

$stmt = $dbconn->prepare("SELECT ST_AsText(ST_Transform(geom, 4326)) AS geom FROM part_athens_centroids WHERE gid = :rowPostGis;");
$stmt->execute(array('rowPostGis' => $rowPostGis));

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $geom = $row['geom'];
    echo($geom);
    //echo($geom);
}   
}

【问题讨论】:

标签: json postgresql postgis


【解决方案1】:

我会研究http://php.net/manual/en/function.explode.php,这会将您的字符串转换为字符串数组,您可以使用http://php.net/manual/en/function.intval.php 将每个字符串转换为int。您可能需要将查询结果裁剪为仅使用 http://php.net/manual/en/function.substr.php 的数字。

【讨论】:

    猜你喜欢
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2018-01-29
    • 2013-08-12
    • 2021-12-27
    • 1970-01-01
    相关资源
    最近更新 更多