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

Inject code after X paragraphs but avoiding tables

i would like to inject some code after X paragraphs, and this is pretty easy with php. public function inject($text, $paragraph = 2) { $exploded = explode("

", $text); if (isset($exploded[$paragraph])) { $exploded[$paragraph] =…
Oscar Fanelli
  • 3,337
  • 2
  • 28
  • 40
4
votes
6 answers

PHP explode and assign it to a multi-dimensional array

i want to explode a string two time and make a multi-dimensional array. $data = "i love funny movies \n i love stackoverflow dot com \n i like rock song"; $data = explode("\n", $data); so a print_r($data); will output: Array ( [0] => i love…
rakibtg
  • 5,521
  • 11
  • 50
  • 73
4
votes
4 answers

find a element in html and explode it for stock

I want to retrieve an HTML element in a page.

Showing 1 - 12 of 40,923 Results

I have to get the total number of results for the test in my php. For now, I get all…
mortiped
  • 869
  • 1
  • 6
  • 28
4
votes
3 answers

PHP explode get specfic index value in one line

I want to do We can access first index easily using stristr($str," ",true); //For php version >= 5.3 or $foo = array_shift(explode(':', $foo)); or…
Wasim A.
  • 9,660
  • 22
  • 90
  • 120
4
votes
3 answers

Explode a string with line break

I am trying to break a string into an array using the explode function. I want it break the string using the line breaks found inside the string. I looked it up and I tried all the ways but I can't get it to work. Here is what I have so far: $r =…
Ara Sivaneswaran
  • 365
  • 1
  • 10
  • 25
4
votes
3 answers

Unexpected bracket '[' - PHP

I'm writing a small repository for my little app team's Java code, and I have this error all over my code. $base = explode(".", $class)[0]; The problem occurs only with this one line of code, every time. As far as I know, the above is correct PHP…
Sammi De Guzman
  • 567
  • 9
  • 20
4
votes
2 answers

PHP Explode with an Unicode character as separator

XPDFs pdftotext converts pdf to text and outputs it at command line level. If needed it inserts PageBreaks between the pages as specified in TextOutputDev.cc: eopLen = uMap->mapUnicode(0x0c, eop, sizeof(eop)); This Unicode symbol is encoding…
sluijs
  • 4,146
  • 4
  • 30
  • 36
4
votes
4 answers

Convert a string to an array - PHP

Possible Duplicate: Load and read a csv file with php I have the following string: Mr,Tom,Jones,Add1,Add2,"Add3,Add3 extra",Town,County,postcode,99999,888,777 I am tring to get the string into an array that looks like the below: Array ( [0]…
makie
  • 41
  • 1
4
votes
2 answers

SQL: Explode an array

I have a table that contains JSON objects. Each JSON object contains an array in square brackets, separated by commas. How can I access any element in the square bracket array, for example "Matt", using SQL? {"str": [ 1, 134, 61, …
Don P
  • 60,113
  • 114
  • 300
  • 432
4
votes
5 answers

Split/parse a PHP string by separate certain words

I've searched the PHP manual, Stackoverflow, and some forums, but I'm stumped on some PHP logic. Maybe I'm just tired, but I'd really appreciate some assistance or direction on this by anybody. I have a PHP string, say: $string = 'cats cat1 cat2…
envysea
  • 1,033
  • 1
  • 9
  • 16
3
votes
2 answers

How to choose between explode and regex

My string is to contain some "hotkeys" of the form [hotkey]. For example: "This is a sample string [red] [h1]" When I process this string with a php function, I'd like function to output the original string as follows;

This…

Average Joe
  • 4,521
  • 9
  • 53
  • 81
3
votes
2 answers

csv parsing, exploding avoiding ""

I have a csv file (really big) that I'm parsing with php. Now is made like this. x,y,z,value,etc but sometimes there is this: x,"blah,blah,blah",z,value,etc doing this: explode(',',$string); In case of a "" value also explode everything…
0plus1
  • 4,475
  • 12
  • 47
  • 89
3
votes
10 answers

Split string on every second space to isolate every two words

Lets say I have a string: $string = "This is my test case for an example." If I do explode based on ' ' I get an Array('This','is','my','test','case','for','an','example.'); What I want is an explode for every other space: Array('This is','my…
AhmedF
3
votes
1 answer

Explode animation with jquery

I have a container with a span tag and if I click the span element I need to have a explode animaton and remove that element. I am able to use fade effect but I am not sure how to use explode effect as If use this way it is just deleting without any…
coder
  • 13,002
  • 31
  • 112
  • 214
3
votes
2 answers

Getting Data From Multi-level Array

Question below. This is the solution I came up with based on Pixeler's answer. $v1) { if (is_array($v1)) { echo $k1."
"; foreach ($v1 as $k2 => $v2) { …