在 PHP 中将字符串转换为数组

Convert a string to array in PHP

我使用 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);
}   
}

我会调查 http://php.net/manual/en/function.explode.php this will convert your string into an array of strings that you can use http://php.net/manual/en/function.intval.php to convert each string to an int. You may need to crop the query result down to just the numbers for that use http://php.net/manual/en/function.substr.php