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
6
votes
2 answers

php parse error explode

I am optimizing my website a bit. Tested the page on local, everything is fine. When I upload it, and access it live, it sudently throws a parse error... but it working perfectly locally, like I said. Parse error: syntax error, unexpected '[',…
user3916429
  • 562
  • 6
  • 25
6
votes
5 answers

PHP line break where lower-case letters meets uppercase-letter

I have a string, that is like the following: $string = "New video gameSome TV showAnother item"; I want to be able to access each item individually, to get something like the following output: New video game Some TV show Another item How can I add…
6
votes
3 answers

PHP explode() - how to avoid blank lines?

I think this code puts a blank line at the end. If that is true, how to avoid this? $text = explode( "\n", $text ); foreach( $text as $str ) { echo $str; }
Yurié
  • 2,148
  • 3
  • 23
  • 40
6
votes
4 answers

Explode string only once on first occurring substring

preg_match() gives one match. preg_match_all() returns all matches. preg_split() returns all splits. How can I split only on the first match? Example: preg_split("~\n~", $string); This is what I want: array( 0 => 'first piece', 1 => 'the rest…
albus
  • 61
  • 1
  • 3
6
votes
3 answers

php url explode

I am wanting to grab my product from my url. For example: http://www.website.com/product-category/iphone I am wanting to grab the iphone and that is fine with my code but I have a dropdown to sort products and which clicked will change the url and…
user1616846
  • 181
  • 1
  • 1
  • 10
6
votes
3 answers

how to select unique keywords from a comma separated tags

I want to retrieve some tags from my database, they are in the form: topic_id tags 1 `tag1,tag2,tag3` 2 `tag1,tag4,tag5` 3 `tag2,tag4,tag5` 4 `tag6,tag7,tag2` I want to have something like this: tag1…
Dot Oyes
  • 163
  • 3
  • 12
5
votes
4 answers

Counting the number of times a character occurs in a string in C

I'm new to C, and I'm working on my own explode like function. I'm trying to count how many times a specified character occurs in a string. int count_chars(char * string, char * chr) { int count = 0; int i; for (i = 0; i <…
Rob
  • 7,980
  • 30
  • 75
  • 115
5
votes
4 answers

php - string trim

Please help me on this. $str = "col_1 col_2 col_3 row1 row2 row3 row12 row22 row33"; $arr = explode("\n", $str); foreach($arr as $line) { $temp_arr = explode(WHAT HERE, $line); } How do I explode each line into array?? I want…
Quy
  • 3
  • 3
5
votes
4 answers

Sorting entities and filtering ListProperty without incurring in exploding indexes

I'm developing a simple Blogging/Bookmarking platform and I'm trying to add a tags-explorer/drill-down feature a là delicious to allow users to filter the posts specifying a list of specific tags. Something like this: Posts are represented in the…
systempuntoout
  • 71,966
  • 47
  • 171
  • 241
5
votes
1 answer

How to explode get_json_object in Apache Spark

I have the following string in one of my dataframe's column: row1:[{"key":"foo"},{"key":"bar"},{"key":"baz"}] row2:[{"key":"foo"},{"key":"bar"}] row3:null etc I found that Spark has "get_json_object" function. So if I want to use xpath to extract…
Mantovani
  • 500
  • 2
  • 7
  • 18
5
votes
2 answers

Php string explode string based on characters match with string condition

I have strings like this: $string1 = '35 Hose & Couplings/350902 GARDEN HOSE COUPLING, PVC, 16\/19 MM"'; $string2 = '35 Hose & Couplings/350904 GARDEN HOSE TAP CONNECTOR, PVC, 3\/4" FEMALE THREAD"'; I tried to separate the string and turn it into …
nortonuser
  • 215
  • 1
  • 7
5
votes
3 answers

Remove part of an NSString

I have an NSString as follows: 996453912Shop4Tech Coupons I only need the first part (before the
Michael Amici
  • 308
  • 1
  • 4
  • 18
5
votes
2 answers

Explode array in apache spark Data Frame

I am trying to flatten a schema of existing dataframe with nested fields. Structure of my dataframe is something like that: root |-- Id: long (nullable = true) |-- Type: string (nullable = true) |-- Uri: string (nullable = true) |-- Type:…
Artem
  • 81
  • 1
  • 1
  • 9
5
votes
4 answers

Explode each values of Array element

I have an array like : Array ( [2] => 2,6 [3] => 1 [4] => 14 [5] => 10 [6] => 8 ) I want to explode each element of an array and return a new array using array_map, so that I can avoid using loop, and creating extra function to call…
Alok Jha
  • 562
  • 7
  • 22
5
votes
2 answers

Spark explode nested JSON with Array in Scala

Lets say i loaded a json file into Spark 1.6 via sqlContext.read.json("/hdfs/") it gives me a Dataframe with following schema: root |-- id: array (nullable = true) | |-- element: string (containsNull = true) |-- checked: array (nullable =…
user3780814
  • 147
  • 1
  • 2
  • 10