标签: explode

有没有办法在mysql语句中爆炸单元格值

我在表格中有列,我将标签ID存储为1 | 5 | 10

我想使用mysql查询来爆炸列

mysql explode

2
推荐指数
1
解决办法
1133
查看次数

我应该使用爆炸,分裂和/或修剪; 如何?

我想从中获得一些价值:

$bounds = '((-34.41859810454894, 150.5594567718506), (-34.375112955999064, 150.74124617004395))';
Run Code Online (Sandbox Code Playgroud)

我的目标是将四个数字中的每一个列为自己的变量:

$swla = -34.41859810454894;
$swlo = 150.5594567718506;
$nela = -34.375112955999064;
$nelo = 150.74124617004395;
Run Code Online (Sandbox Code Playgroud)

这是我糟糕的黑客尝试:

$pieces = explode("),", $bounds);
var_dump($pieces); //array(2) { [0]=> string(39) "((-34.41859810454894, 150.5594567718506" [1]=> string(43) " (-34.375112955999064, 150.74124617004395))" } 
echo '<br />';

$sw = trim(substr($pieces[0], 2));
echo $sw .'<br />'; //-34.41859810454894, 150.5594567718506
$ne = trim(substr($pieces[1], 2), " ) ");
echo $ne.'<br />'; //-34.375112955999064, 150.74124617004395

$sw = explode(",", $sw);
var_dump($sw); //array(2) { [0]=> string(18) "-34.41859810454894" [1]=> string(18) " 150.5594567718506" } 
echo '<br …
Run Code Online (Sandbox Code Playgroud)

php google-maps trim explode

2
推荐指数
1
解决办法
522
查看次数

使用正则表达式分解字符串

我有一个如下的字符串(示例中的字母可以是数字或文本,可以是大写或小写或两者。如果值是一个句子,则它应该位于单引号之间):

$string="a,b,c,(d,e,f),g,'h, i j.',k";
Run Code Online (Sandbox Code Playgroud)

我怎样才能将其分解以获得以下结果?

Array([0]=>"a",[1]=>"b",[2]=>"c",[3]=>"(d,e,f)",[4]=>"g",[5]=>"'h,i j'",[6]=>"k")
Run Code Online (Sandbox Code Playgroud)

我认为使用正则表达式将是一种快速且干净的解决方案。任何想法?

编辑: 这是我到目前为止所做的,对于括号之间有很长部分的字符串来说非常慢:

$separator="*"; // whatever which is not used in the string
$Pattern="'[^,]([^']+),([^']+)[^,]'";
while(ereg($Pattern,$String,$Regs)){
    $String=ereg_replace($Pattern,"'\\1$separator\\2'",$String);
}

$Pattern="\(([^(^']+),([^)^']+)\)";
while(ereg($Pattern,$String,$Regs)){
    $String=ereg_replace($Pattern,"(\\1$separator\\2)",$String);
}

return $String;
Run Code Online (Sandbox Code Playgroud)

这将替换括号之间的所有逗号。$separator然后我可以用逗号将其分解并用原始逗号替换。

php regex arrays explode

2
推荐指数
1
解决办法
6619
查看次数

用逗号和新行一起爆炸

我有一个基本的文本区域。当用户输入一些文本时,我用逗号“,”分解单词。现在我也想用新行分隔单词。我该怎么做。

这是我的代码部分,用逗号分解单词。

if(isset($_POST["btn"])){
    $words     = $_POST["inp_text"];
    $words_arr = explode(",",$words);

    foreach($words_arr as $word){
        echo $word."<br>";
    }
}
Run Code Online (Sandbox Code Playgroud)

如何向此代码部分添加新行功能。我想,我应该从$word循环中生成一个字符串而不是循环之后我应该再次用新行分解这个字符串。

有更好的主意吗?

为了更好地理解,我添加了一些示例。

输入:

apple, melon, a, b, c
Run Code Online (Sandbox Code Playgroud)

输出:

apple melon a b c
Run Code Online (Sandbox Code Playgroud)

输入(带新行)

x,y,z,a
b
c
Run Code Online (Sandbox Code Playgroud)

输出:

x y z a b c
Run Code Online (Sandbox Code Playgroud)

php arrays string explode

2
推荐指数
1
解决办法
2830
查看次数

如何通过多个分隔符来分解字符串并保留分隔符?

我正在尝试使用多个分隔符(?? , ? , ?? , ?)来分解字符串.

例如,我有这个输入字符串:

$string = "(2.8 , 3.1) ? (??2.4 , ?3.0)";
Run Code Online (Sandbox Code Playgroud)

我想将它转换为这样的数组(预期输出):

Array
(
    [0] => (2.8 , 3.1) ? (
    [1] => ??
    [2] => 2.4 , 
    [3] => ?
    [4] => 3.0)
)
Run Code Online (Sandbox Code Playgroud)

我最好的尝试打印我(当前输出):

Array
(
    [0] => (2.8 , 3.1) ? (
    [1] => ?
    [2] => ?2.4 , 
    [3] => ?3.0)
)
Run Code Online (Sandbox Code Playgroud)

这是我目前的代码:

<?php

    function multiexplode ($delimiters,$string) {
        return explode(
            $delimiters[0],
            strtr(
                $string,
                array_combine(
                    array_slice($delimiters,1),
                    array_fill(0,count($delimiters)-1,array_shift($delimiters))
                )
            ) …
Run Code Online (Sandbox Code Playgroud)

php regex string explode preg-split

2
推荐指数
1
解决办法
3927
查看次数

php - 如何使用斜杠(/)中的laravel爆炸并获得最后一个单词

嗨我真的是Laravel的新手.所以我真的需要一些帮助,我需要从$ report-> reportable_type获取最后一个字,并从reportable_type获取它包含App/Models/Store和App/Models/Product.所以我想爆炸斜杠(/)并得到它意味着商店或产品的最后一个字.

我的控制器中的代码工作但它使用print_r,我不想使用print_r.

这是我的控制器

public function toLink($id)
{
    $report = $this->reportRepository->findWithoutFail($id);

    //get Store Name
    $name = Store::where('id','=',$report->reportable_id)->pluck('name')->all();
    $storename = $name[0];

    //get Store ID
    $idstore = Store::where('id','=',$report->reportable_id)->pluck('id')->all();
    $storeid = $idstore[0];

    if(empty($report))
    {
        Flash::error('Report not found');
        return redirect(route('reports.index'));
    }

    $report_type = $report->reportable_type;
    print_r (explode("/",strrpos($report_type, '/') + 1),$report_type);
    return redirect(env('FRONTEND_URL') ."/".str_slug($reportable_type)."/$storeid/".str_slug($storename));


}
Run Code Online (Sandbox Code Playgroud)

php explode laravel

2
推荐指数
1
解决办法
626
查看次数

分解多个长度不同的相同类型的柱子

我有一个需要分解的格式如下的火花数据框。我检查了其他解决方案,例如这个。但是,就我而言,before并且after可以是不同长度的数组。

root
 |-- id: string (nullable = true)
 |-- before: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- start_time: string (nullable = true)
 |    |    |-- end_time: string (nullable = true)
 |    |    |-- area: string (nullable = true)
 |-- after: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- start_time: string (nullable = true)
 |    |    |-- end_time: string (nullable = true) …
Run Code Online (Sandbox Code Playgroud)

scala explode apache-spark apache-spark-sql

2
推荐指数
1
解决办法
890
查看次数

在pyspark中分解Maptype列

我有一个像这样的数据框

data = [(("ID1", {'A': 1, 'B': 2}))]
df = spark.createDataFrame(data, ["ID", "Coll"])
df.show()

+---+----------------+
| ID|            Coll|
+---+----------------+
|ID1|[A -> 1, B -> 2]|
+---+----------------+

df.printSchema()
root
 |-- ID: string (nullable = true)
 |-- Coll: map (nullable = true)
 |    |-- key: string
 |    |-- value: long (valueContainsNull = true)
Run Code Online (Sandbox Code Playgroud)

我想分解“Coll”列,以便

+---+-----------+
| ID| Key| Value|
+---+-----------+
|ID1|   A|     1|
|ID1|   B|     2| 
+---+-----------+
Run Code Online (Sandbox Code Playgroud)

我正在尝试在 pyspark 中执行此操作

如果我只使用一列,我就会成功,但我也想要 ID 列

df.select(explode("Coll").alias("x", "y")).show()

+---+---+
|  x|  y|
+---+---+
|  A| …
Run Code Online (Sandbox Code Playgroud)

explode apache-spark apache-spark-sql pyspark

2
推荐指数
1
解决办法
8304
查看次数

将 Pandas 数据框日期范围扩展到单个行

我必须根据开始日期和结束日期将 Pandas 数据框扩展为单独的行。

原始数据框如下

原始数据框

我的最终数据框应该在各个行的开始日期和结束日期之间的每一天重复。结果需要为每个日期扩展,而除“开始日期”和“结束日期”之外的其他列都保留。

例如,startdate = 01-Jan-20 和 enddate 15-Jan-20 的第一行应该扩展为 15 个单独的行,代表系列中的一个日期,如此处的示例结果数据帧所示:

预期结果数据框

我尝试使用 itertuples 的解决方案来迭代数据帧并将范围分解为单个日期,但是当数据帧的大小很大时,该解决方案很慢。

任何关于此的最佳解决方案都受到高度赞赏。

date-range explode dataframe pandas

2
推荐指数
1
解决办法
2007
查看次数

我应该使用\ r或\n来爆炸()PHP中文件的内容吗?

我正在创建一个函数,它可以接受一个字符串,该字符串可以通过file_get_contents()本地文本文件检索,也可以从URL中获取http://site.com/338383.txt.

该文件将是一个选项卡分隔文件,文件中的每个项目都在其自己的行上.它是更好地使用\n或\r以explode()串并得到各行的阵列?

我注意到在某些情况下\n不起作用.我想要一贯有效的方法.有什么想法吗?

php string explode

1
推荐指数
1
解决办法
1127
查看次数