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

Is explode equivalent to implode when using the same parameter?

Let's say I have the following function: public function normalize($string) { $substrings = explode(",", $string); return implode(",", $substrings); } Will ($string == normalize($string)) always be true? is there any special case I should…
Alfred
  • 73
  • 6
4
votes
3 answers

Explode string on commas and pipes to create two arrays

I did coding as below and got the wrong output: $asst_vicars_data_arr=explode(',',$asst_vicars_data); $asst_head_type_count=count($asst_vicars_data_arr); $d = explode("|",$data); foreach ($asst_vicars_data_arr as $value) { $arr =…
Dayz
  • 269
  • 2
  • 12
4
votes
4 answers

Parse string containing two numbers and assign them to two variables

$pos contains two numbers delimited by a space in one string. $pos = 98.9 100.2 How can I split this into 2 variables? I obviously have to check for the space in between. I would like to have two variables afterwards: $number1 = 98.9 $number2 =…
algro
  • 639
  • 4
  • 8
  • 25
4
votes
3 answers

How to cast a string to array of struct in HiveQL

I have a hive table with the column "periode", the type of the column is string. The column have values like the…
4
votes
2 answers

How to wrap every word in spans with PHP?

I have a some html paragraphs and I want to wrap every word in . Now I have $paragraph = "This is a paragraph."; $contents = explode(' ', $paragraph); $i = 0; $span_content = ''; foreach ($contents as $c){ $span_content .= ''.$c.'
user2335065
  • 2,337
  • 3
  • 31
  • 54
4
votes
3 answers

Mysql query explode and count

I have table like this: product_id model date computers ---------------------------------------------------------------- 12204 Asus 'random_date' :::aass:::ddff:::ddfd:::dfwr::: 12205 …
Gereltod
  • 2,043
  • 8
  • 25
  • 39
4
votes
6 answers

MySQL (exploding/matching array)

Question1: MySQL table id | array 1 | 1,2,3 2 | 2 3 | 2,3 4 | 4,5,6 $_GET['id'] = 2; $a = mysql_query("SELECT * FROM `table` WHERE `array` ??? '$_GET[id]'"); In this step, I want to run through the entire array and see if it matches with the…
user317005
4
votes
3 answers

end(explode) Strict Standards: Only variables should be passed by reference in

I have this code to get the extension of a file: $extension = end(explode(".", $_FILES["rfile"]["name"])); That is working fine on localhost, but when I upload online hosting, it is giving me this error: Strict Standards: Only variables should be…
Elyor
  • 5,396
  • 8
  • 48
  • 76
4
votes
1 answer

mysql query with explode

I have a table with this type of value 20|10|5|8|19| (with separator) I need to select rows, where first value (for example after explode), less than 20. $arr = explode("|", "goal_times"); $first_goal_time = $arr[0]; But how to do this in Mysql…
4
votes
2 answers

To explode the string based on the special characters in Php

I have a string: xyz.com?username="test"&pwd="test"@score="score"#key="1234" output format: array ( [0] => username="test" [1] => pwd="test" [2] => score="score" [3] => key="1234" )
sac
  • 137
  • 2
  • 5
  • 15
4
votes
2 answers

Exploding and trimming a long string effectively resulting in a single array

I'm trying to create a messaging system where you can send to a single or multiple users at the same time. The value which is delivered from my form looks like this: Now, in order for me to post…
Gjert
  • 1,069
  • 1
  • 18
  • 48
4
votes
1 answer

Trying to get forums to display all subcategories with category

This is what my forums currently look like: http://prntscr.com/73oicl But, as you can see, the categories both say "community", which isn't supposed to happen. The "Test" subcategory should be right under the "Announcements & Updates" subcategory. I…
Joel E
  • 103
  • 1
  • 7
4
votes
1 answer

Echo the ending part or last folder of $_SERVER['DOCUMENT_ROOT'] in PHP

I need to use $_SERVER['DOCUMENT_ROOT']; to scandir for files and folders to display for my nav menu. Let's say my root directory is at /home/user/public_html/website/. Here's how I echo the root directory: echo $_SERVER['DOCUMENT_ROOT']; it will…
Mike
  • 607
  • 8
  • 30
4
votes
4 answers

Split file up based on delimiters in php - which is the best to use?

I am trying to parse a file using php but I am not sure of the best way to do it. The file consists of stuff like: saturn+5 57 space+shuttle 34 gemini 12 mercury 2 soyuz+tm 1 What I'm trying to do is split it up and populate a hash map,…
user3713442
  • 478
  • 8
  • 22
4
votes
2 answers

Replace use of explode() with str_split()

$transData = fgets($fp); while (!feof ($fp)) { $transArry = explode(" ", $transData); $first = $transArry[0]; $last = $transArry[1]; $Sub = $transArry[2]; $Grade= $transArry[3]; echo "
user289346
  • 487
  • 2
  • 6
  • 7