Questions tagged [explode]

explode() is a PHP function that splits a string based on a delimiter, returning an array.

explode() is a PHP function that splits a string based on a delimiter, returning an array.

array explode ( string $delimiter , string $string [, int $limit ] )

Example

$text = "a b c d";
print_r(explode(" ", $text));

gives:

Array ( [0] => a [1] => b [2] => c [3] => d )
2123 questions
4
votes
3 answers

I am trying to split/explode/preg_split a string but I want to keep the delimiter

I am trying to split/explode/preg_split a string but I want to keep the delimiter example : explode('/block/', '/block/2/page/2/block/3/page/4'); Expected result : array('/block/2/page/2', '/block/3/page/4'); Not sure if I have to loop and then…
Purplefish32
  • 647
  • 1
  • 8
  • 24
4
votes
2 answers

How do you EXPLODE CSV line with a comma in value?

"AMZN","Amazon.com, Inc.",211.22,"11/9/2011","4:00pm","-6.77 - -3.11%",4673052 Amazon.com, Inc. is being treated as 2 values instead of one. I tried this $data = explode( ',', $s); How do I modify this to avoid the comma in the value issue?
ThinkCode
  • 7,841
  • 21
  • 73
  • 92
4
votes
2 answers

Explode empty line

I am trying to explode empty line. Here is my string variable: $string = ' Hello, Just test lines Second test lines '; I want these results: $OUTPUT[0]='HELLO,'; $OUTPUT[1]='Just test lines Second test lines'; My code: $a =…
Emad doom
  • 87
  • 2
  • 6
4
votes
2 answers

Rust Polars: Is it possible to explode a list column into multiple columns?

I have a function which returns a list type column. Hence, one of my columns is a list. I'd like to turn this list column into multiple columns. For example: use polars::prelude::*; use polars::df; fn main() { let s0 = Series::new("a", &[1i64,…
Anatoly Bugakov
  • 772
  • 1
  • 7
  • 18
4
votes
3 answers

How does one break a string down by capital letters with PHP?

I have a string: CamelCaseString I want to explode(), split(), or some better method on capital letters to break this string down into the individual words. What's the simplest way to do this? --- SOLUTION UPDATE --- This link is to a slightly…
T. Brian Jones
  • 13,002
  • 25
  • 78
  • 117
4
votes
2 answers

How to create a new 'index' column after using pandas DataFrame.explode()?

I'm using DataFrame.explode() to unnest a column of lists such that each element gets its own row. What I'm wondering is how to create a new 'index' column that will correspond to the index of the element in the original list. In the example I'm…
ZachGutz
  • 51
  • 4
4
votes
1 answer

Pyspark : How to split pipe-separated column into multiple rows?

I have a dataframe that contains the following: movieId / movieName / genre 1 example1 action|thriller|romance 2 example2 fantastic|action I would like to obtain a second dataframe (from the first one), that contains the…
Codegator
  • 459
  • 7
  • 28
4
votes
4 answers

Pandas explode error - column must be scalar

df.explode(['X']) ValueError: column must be a scalar Hi anyone could advice on this?
Tonz
  • 177
  • 1
  • 2
  • 11
4
votes
5 answers

explode error \r\n and \n in windows and linux server

I have used explode function to get textarea's contain into array based on line. When I run this code in my localhost (WAMPserver 2.1) It work perfectly with this code : $arr=explode("\r\n",$getdata); When I upload to my linux server I need to…
Aryan G
  • 1,281
  • 10
  • 30
  • 51
4
votes
3 answers

PHP explode strings, but treat words in quotes as a single word

How can I explode the following string: "foo bar"ANDbar"foo"AND"foofoo" lorem "impsum" into array('"foo bar"', 'ANDbar', '"foo"', 'AND',' "foofoo"', "lorem", '"impsum"') I check this answer : https://stackoverflow.com/a/2202489/11398085 but not…
Yannik
  • 43
  • 8
4
votes
8 answers

PHP Insert Multiple Spaces

I've got some data that needs to be cleaned up into a fixed length format. I'm using PHP to grab the data out, covert it, and put it back in, but it's not working as planned. There is a certain point in each piece in the middle of the data where…
bmbaeb
  • 520
  • 1
  • 8
  • 15
4
votes
9 answers

Shortcut for: $foo = explode(" ", "bla ble bli"); echo $foo[0]

is there a way to get the n-th element of a splitted string without using a variable? My PHP code always looks like this: $foo = explode(" ", "bla ble bli"); echo $foo[0]; Is there a shorter way maybe like in Python? print "bla ble bli".split("…
KebdnK
  • 555
  • 1
  • 6
  • 23
4
votes
1 answer

How to explode the dataset in JSON file by using explode functionality in R?

Note - I have referred answer, but although the data is un-nested but I could not convert data into csv file format. I want to flatten the data of different data types by using explode functionality. The dataset contains arrays and structure. I want…
Shree
  • 203
  • 3
  • 22
4
votes
3 answers

php vs javascript speed for processing information

I have a database that contains strings in the format: "key:value|key:value|key:value|key:value" Due to some other reasons, I can not have the key value pairs stored in the database. Should I use PHP to split the string and pass it into the…
akshaykarthik
  • 1,055
  • 2
  • 13
  • 30
4
votes
3 answers

Is it possible to explode string like a pagination?

For example: $string = '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15'; And then explode it like a pagination, for example 8 values each row will result in two 2 pages: $arr = p_explode(',', $string, 8); array( 0 => "1,2,3,4,5,6,7,8" 1 =>…
Diogo Garcia
  • 536
  • 1
  • 8
  • 20