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
7
votes
3 answers

PHP Generate IP Ranges

As you know, range() function can get a range between number and the other, how to do the same with an IP as example.. $range_one = "1.1.1.1"; $range_two = "1.1.3.5"; print_r( range($range_one, $range_two) ); /* I want a result of : …
Osa
  • 1,922
  • 7
  • 30
  • 51
7
votes
5 answers

Can we do multiple explode statements on one line in PHP?

Can we do multiple explode() in PHP? For example, to do this: foreach(explode(" ",$sms['sms_text']) as $no) foreach(explode("&",$sms['sms_text']) as $no) foreach(explode(",",$sms['sms_text']) as $no) All in one explode like…
Harinder
  • 1,257
  • 8
  • 27
  • 54
6
votes
3 answers

PHP: Explode textarea lines as separate array element

I have a textarea that contains phone numbers, each number in a separate line. I want to explode that string into an array using explode("\n", $numbers); or explode("\r\n", $numbers); This is not working. Please, help me. Thanks!
Sergiu Svet
  • 101
  • 1
  • 2
  • 8
6
votes
3 answers

Parsing: library functions, FSM, explode() or lex/yacc?

When I have to parse text (e.g. config files or other rather simple/descriptive languages), there are several solutions that come to my mind: using library functions, e.g. strtok(), sscanf() a finite state machine which processes one char at a…
Philip
  • 5,795
  • 3
  • 33
  • 68
6
votes
1 answer

PySpark "explode" dict in column

I have a column 'true_recoms' in spark dataframe: -RECORD 17----------------------------------------------------------------- item | 20380109 …
Jackson
  • 61
  • 1
  • 1
  • 2
6
votes
6 answers

how to remove comma white space during explode and replace?

$data = "google,facebook,youtube,twitter,bing"; $exp = explode(",",$data); $rep = str_replace("facebook",$exp); $final = implode(",",$rep); echo $final output// google,,youtube,twitter,bing How can I remove this blank space with comma?
limo
  • 225
  • 5
  • 12
6
votes
1 answer

Python - Pandas - DataFrame - Explode single column into multiple boolean columns based on conditions

Good morning chaps, Any pythonic way to explode a dataframe column into multiple columns with boolean flags, based on some condition (str.contains in this case)? Let's say I have this: Position Letter 1 a 2 b 3 c …
Trostis
  • 73
  • 5
6
votes
1 answer

Hive : How to explode a JSON column with an array, and embedded in a CSV file?

From a CSV file (with a header and a pipe delimiter) I've got the following content which contains a JSON column (with a collection inside), like…
prossblad
  • 688
  • 1
  • 7
  • 11
6
votes
1 answer

Hive : How to explode a JSON column embedded in a CSV file?

From a CSV file (with a header and a pipe delimiter) I've got the two following contents which contain a JSON column (with a collection inside), like this: First case (with a JSON collection with no…
prossblad
  • 688
  • 1
  • 7
  • 11
6
votes
3 answers

Explode multiple columns in Spark SQL table

There was a question regarding this issue here: Explode (transpose?) multiple columns in Spark SQL table Suppose that we have extra columns as below: **userId someString varA varB varC varD** 1 "example1" [0,2,5] …
Mohd Zoubi
  • 186
  • 3
  • 16
6
votes
1 answer

Spark dataframe add a row for every existing row

I have a dataframe with following columns: groupid,unit,height ---------------------- 1,in,55 2,in,54 I want to create another dataframe with additional rows where unit=cm and height=height*2.54. Resulting…
dreddy
  • 463
  • 1
  • 7
  • 21
6
votes
5 answers

How do I change the delimiter of a list?

$variable = 'one, two, three'; How can I replace the commas between words with
? $variable should become: one
two
three
James
  • 42,081
  • 53
  • 136
  • 161
6
votes
1 answer

Deep (infinite) NESTED split words using regex

IMPORTANT EDIT: Since many people said that this should be avoided and almost unable to do using RegEx, I'm going to allow you for some other solutions. As from now on, any solution could be used as an answer and finally a solution. Thanks! Lets…
J. Doe
  • 93
  • 6
6
votes
2 answers

Scala DataFrame: Explode an array

I am using the spark libraries in Scala. I have created a DataFrame using val searchArr = Array( StructField("log",IntegerType,true), StructField("user", StructType(Array( StructField("date",StringType,true), …
Jaume Primer
  • 61
  • 1
  • 6
6
votes
2 answers

Explode string when not between ()

I'm trying to explode an string by comma's: , but only when it's not between parenthesis (...) Here's some code to show what I mean: $string = "K.VisueelNr,IFNULL(P.Partijnaam, 'Leeg gemeld') AS Partijnaam,R.Ras,M.Maat,DATE_FORMAT(KS.Timestamp,…
Mathlight
  • 6,436
  • 17
  • 62
  • 107