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 )
1992 questions
26
votes
5 answers

Calling PHP explode and access first element?

Possible Duplicate: PHP syntax for dereferencing function result I have a string, which looks like 1234#5678. Now I am calling this: $last = explode("#", "1234#5678")[1] Its not working, there is some syntax error...but where? What I expect is…
EOB
  • 2,749
  • 17
  • 40
  • 68
23
votes
2 answers

PHP: How can I explode a string by commas, but not wheres the commas are within quotes?

I need to explode my string input into an array at the commas. However the string contains commas inside quotes. Input: $line = 'TRUE','59','A large number is 10,000'; $linearray = explode(",",$line); $linemysql =…
Nicekiwi
  • 4,117
  • 9
  • 44
  • 81
22
votes
3 answers

How do I explode an integer

the answer to this could be easy. But I'm very fresh to programming. So be gentle... I'm at work trying to do a quick fix for one of your customers. I want to get the total numbers of digits in a integer, and then explode the integer: rx_freq =…
chriscandy
  • 335
  • 1
  • 2
  • 7
22
votes
3 answers

In PHP, which is faster: preg_split or explode?

This may sound like a stupid question, but: which is faster when using it to extract keywords in a search query in php: $keyword = preg_split('/[\s]+/', $_GET['search']); or $keyword = explode(' ', $_GET['search']);
Marco
  • 2,435
  • 4
  • 35
  • 56
22
votes
6 answers

php explode: split string into words by using space a delimiter

$str = "This is a string"; $words = explode(" ", $str); Works fine, but spaces still go into array: $words === array ('This', 'is', 'a', '', '', '', 'string');//true I would prefer to have words only with no spaces and keep the information…
Haradzieniec
  • 8,150
  • 26
  • 100
  • 199
22
votes
2 answers

Is there an equivalent in C++ of PHP's explode() function?

Possible Duplicate: Splitting a string in C++ In PHP, the explode() function will take a string and chop it up into an array separating each element by a specified delimiter. Is there an equivalent function in C++?
reformed
  • 3,922
  • 9
  • 51
  • 77
21
votes
5 answers

Exploding by Array of Delimiters

Is there any way to explode() using an array of delimiters? PHP Manual: array explode ( string $delimiter , string $string [, int $limit ] ) Instead of using string $delimiter is there any way to use array $delimiter without affecting performance…
JoeC
  • 327
  • 2
  • 3
  • 9
20
votes
5 answers

Hive Explode / Lateral View multiple arrays

I have a hive table with the following schema: COOKIE | PRODUCT_ID | CAT_ID | QTY 1234123 [1,2,3] [r,t,null] [2,1,null] How can I normalize the arrays so I get the following result COOKIE | PRODUCT_ID | CAT_ID | QTY 1234123 …
user2726995
  • 2,024
  • 2
  • 17
  • 26
19
votes
13 answers

How to explode only on the last occurring delimiter?

$split_point = ' - '; $string = 'this is my - string - and more'; How can I make a split using the second instance of $split_point and not the first one. Can I specify somehow a right to left search? Basically how do I explode from right to left. I…
Codex73
  • 5,445
  • 9
  • 53
  • 75
19
votes
7 answers

undefined offset when using php explode()

I've written what I thought was a very simple use of the php explode() function to split a name into forename and surname: // split name into first and last $split = explode(' ', $fullname, 2); $first = $split[0]; $last = $split[1]; However, this…
musoNic80
  • 3,548
  • 9
  • 37
  • 48
19
votes
4 answers

Explode and get a value in one line of code

Can you write the following in one line of code? $foo = explode(":", $foo); $foo = $foo[0];
Emanuil Rusev
  • 31,853
  • 50
  • 124
  • 193
17
votes
2 answers

Split into two variables?

Say I have the following: "44-xkIolspO" I want to return 2 variables: $one = "44"; $two = "xkIolspO"; What would be the best way to do this?
Latox
  • 4,442
  • 15
  • 44
  • 73
17
votes
2 answers

Split a MYSQL string from GROUP_CONCAT into an ( array, like, expression, list) that IN () can understand

This question follows on from MYSQL join results set wiped results during IN () in where clause? So, short version of the question. How do you turn the string returned by GROUP_CONCAT into a comma-seperated expression list that IN() will treat as a…
user56reinstatemonica8
  • 27,132
  • 16
  • 87
  • 109
17
votes
7 answers

PHP string console parameters to array

I would like to know how I could transform the given string into the specified array: String all ("hi there \(option\)", (this, that), other) another Result wanted (Array) [0] => all, [1] => Array( [0] => "hi there \(option\)", [1] =>…
Cristiano Santos
  • 2,055
  • 2
  • 33
  • 47
14
votes
9 answers

how to count the words in a specific string in PHP?

I want to count the words in a specific string , so I can validate it and prevent users to write more than 100 words for example . I wrote this function but I don't think it's effective enough , I used the explode function with space as a delimiter…
Waseem Senjer
  • 996
  • 3
  • 12
  • 25