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
5
votes
1 answer

Exploding an array that may only have one value

I am not sure if this is doable or if its a bigger problem with in my code but I have a webpage where a user selects some values from a infinite amount. So for example there select a1 and b2 from my form. The form then combines them so they become…
snookian
  • 863
  • 6
  • 13
  • 35
5
votes
7 answers

How to use the explode function in PHP using 2 delimeters instead of 1?

Suppose I have the following: $string = "(a) (b) (c)"; How would I explode it to get the contents inside the parenthesis. If the string's contents were separated by just one symbol instead of 2 I would have used: $string = "a-b-c"; explode("-",…
Georgy
  • 1,067
  • 2
  • 10
  • 7
5
votes
3 answers

Split a string into two equal length parts using PHP

I need to split a string into two equal length parts.String can contain blank spaces, commas or anything. I have referred and tries the code sample of explode statement from the link…
syam
  • 106
  • 2
  • 9
5
votes
3 answers

How can i take only some specific data by explode?

In my following code I can explode and get my 3 elements imei,lat,lon as the response was returning only the 3 data separated by ' '. $r = socket_recvfrom($sock, $buf, 512, 0, $remote_ip, $remote_port); echo "$remote_ip : $remote_port -- " .…
hhs
  • 309
  • 1
  • 3
  • 13
5
votes
4 answers

Split PHP String of a URL

How can i return just the TLD of a domain name for example, if i had the following: www.domain.co.uk i want to return just the .co.uk and the same for domain.co.uk and the same for all other TLDs (.com, .co, .org etc) Is there an easy way to do…
charlie
  • 415
  • 4
  • 35
  • 83
5
votes
7 answers

Isolate substring at end of string after a specific substring

My query generates a result set of UID values which looks like: 855FM21 855FM22 etc I want to isolate the last number from the UID which it can be done by splitting the string. How to split this string after the substring "FM"?
Akhil P M
  • 174
  • 1
  • 2
  • 13
5
votes
4 answers

Use PHP to convert text file into array

I have a text file here which I need to be able to convert into rows to extract the second, third, fourth, and fifth values from. The first 7 values of each row are tab delimited, then there is a newline, then the final three values are tab…
Malignus
  • 73
  • 1
  • 2
  • 6
5
votes
6 answers

Explode to array and print each element as list item

I have a set of numbers in a table field in database, the numbers are separated by comma ','. I am trying to do the following: Step 1. : SELECT set of numbers from database and explode it to array : $array = explode(',', $set_of_numbers); Step 2.…
user2170133
  • 79
  • 3
  • 3
  • 11
5
votes
3 answers

Explore a COM Object in PHP

What would be the proper way to explode a COM object for debugging? I have a 3rd party function that returns a multilevel object. The documentation is non existant, so I'd like to be able to echo everything out of the object or debug it in Komodo…
shaiss
  • 2,000
  • 5
  • 22
  • 33
5
votes
1 answer

PHP: Explode using special characters

I'm working on a long string grabbed from a Session that uses "§" (Section sign) to group and divide different parts of the string. Example: "ArticleID | Title | Date § ArticleID | Title | Date § ArticleID | Title | Date" I want to put this into an…
ticallian
  • 1,631
  • 7
  • 24
  • 34
5
votes
3 answers

PHP equivalent of list and explode in javascript

Possible Duplicate: Javascript equivalent of PHP’s list() I want an equivalent of this line but in JavaScript : Where : $IdALL = '1, 2, 3'; Is there any way to do that with…
Sami El Hilali
  • 981
  • 3
  • 12
  • 21
5
votes
4 answers

Explode contents of a txt file into array

I´m having trouble exploding contents of a .txt file (structure below): 01Name 1 02whatever contents 03whatever contents ------------------- 01Name 2 02whatever contents 03whatever contents As you can see, the…
MrsSammartino
  • 53
  • 1
  • 1
  • 4
5
votes
2 answers

PHP explode string vs array?

Is there a reason to use a string where an array will be required? I have a developer who wants to pass a deliminated string, explode it in a database class method to pull out multiple field/value pairs from 2 separate strings. I can't think of a…
Desirea Herrera
  • 421
  • 4
  • 9
5
votes
4 answers

How to get substring of comma delimited string?

I have a comma delimited string and want the first 100 entries (not including the 100th comma) as a single string. So for example if I had the string a,b,c,d,e,f,g And the problem was get the first 3 entries, the desired result string would…
Hard worker
  • 3,916
  • 5
  • 44
  • 73
4
votes
4 answers

Multi word search in PHP/MySQL

I'm struggling to create a search that searches for multiple words. My first attempt yielded no results whatsoever and is as follows: require_once('database_conn.php'); if($_POST){ $explodedSearch = explode (" ", $_POST['quickSearch']); …
Richie
  • 364
  • 3
  • 8
  • 20