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

Read from file and and use explode function

I need help. I have a file that include numbers: 105 5001 5450 1548 5158 7875 8785 2404 5410 1548 0 0 Now should read from this file then save number of a line and apart that (where it has space between numbers.)and save it on Variable. For…
user3994255
0
votes
1 answer

PHP: Explode string on more than 2 dashes in string

I want explode a string to array with 2 dashes or more. For example I have a string such as "size--medium" or "size---medium" or "size----medium" or this pattern with more than 2 dashes, I want explode them to: Array( 0 => size, 1 =>…
Pooya Saberian
  • 971
  • 2
  • 9
  • 16
0
votes
2 answers

Stop insert on duplicate

I have this code that insert email from array. The email column is set to unique so no duplication should happen. $pieces = explode(",", $email); if (!empty($pieces)){ foreach ($pieces as $value) { mysqli_query($con,"INSERT INTO name…
sg552
  • 1,521
  • 6
  • 32
  • 59
0
votes
1 answer

check the checkbox if the data is same with database

Cannot find out what problems,for example at the beginning i add patient details, i selected allergies and asthma and store into database,but i want to edit the details, it only checked asthma (last value)...please help me find out the answer Thank…
phpnewbie123
  • 25
  • 1
  • 8
0
votes
2 answers

Fix for convert fraction short PHP snippet, issue with calculation converting a fraction to more readable format

Here is the problem, when it encounters fractions like: 300/10 instead of giving a result of "30" the following code gives me: 1/0 $tokens = explode('/', $value); while ($tokens[0] % 10 == 0) { $tokens[0] = $tokens[0] / 10; $tokens[1] =…
htfree
  • 331
  • 1
  • 15
0
votes
2 answers

I need to find a way explode a specific string that has quotes in it

I'm having serious trouble with this and I'm not really experienced enough to understand how I should go about it. To start off I have a very long string known as $VC. Each time it's slightly different but will always have some things that are the…
Zei
  • 3
  • 5
0
votes
1 answer

how can I split array by delimiter

I got string that I split using 'explode()'.But I need some more steps to do.I have to split that array output few more times by delimiter. The txt file's contents look like …
Salim Khan
  • 53
  • 1
  • 12
0
votes
1 answer

How to get from index x to the last one in PHP explode()?

I have a string: $string = 'Index 1 - Index 2 - Index 3 - Index 4 - Index 5'; So I use: $string2 = explode(" - ",$string); I would like to get Index 3 to the last index: Index 3 - Index 4 - Index 5.... Like: $newstring =…
0
votes
4 answers

explode single variable in php

Here is what i have in php : I need to do explode the given variable $a = "hello~world"; I need to explode as $first = "hello"; $second = "world"; How can i do this ?? Here is what i have tried so far.
SA__
  • 1,782
  • 3
  • 20
  • 41
0
votes
3 answers

Querystring parameter explode str_replace array works for only 1 of the delimiters

I am using a explode and str_replace on the get parameter of the query string URL. My goal is to split the strings by certain characters to get to the value in the string that I want. I am having issues. It should work but doesn't. Here are two…
Mike
  • 607
  • 8
  • 30
0
votes
1 answer

Extract information from string to arrays

Hello I am not really familiar with fancy stuff that can be done with php, so i could do 200line function, when pros could do it better in few fabolus lines. Lets say i receive string that looks like [{ "id":…
Newb
  • 27
  • 1
  • 6
0
votes
1 answer

PHP: How to split a string at keyword

I am trying to split a string at keyword "http://". explode("http://", $input); This doesn't work for me because it does not only split the $input but it also deletes "http://" from the string, which i don't want to happen. What is the most…
dimitris93
  • 4,155
  • 11
  • 50
  • 86
0
votes
1 answer

Split paragraphs into multidimensional array

I'm trying to put some HTML-informations in an array.

Title 1

Content 1

Content 2

Title 2

Content 1

Content 2

Content 3

I want to put…
user3142695
  • 15,844
  • 47
  • 176
  • 332
0
votes
1 answer

Explode object variable in Smarty

I'm using the HybridAuth library to display a list of user contacts from Gmail. The object member is displayName and I'm using it like this: {foreach from=$contacts key=k item=contact}
davidcondrey
  • 34,416
  • 17
  • 114
  • 136
0
votes
3 answers

Fetch row and explode - PHP mySQL

Here is my code: $postsql = "SELECT * FROM post WHERE id='{$_GET['id']}'"; $posts = mysqli_query($connect,$postsql) or die("Error: ".mysqli_error($connect)); $post = mysqli_fetch_array($posts); $postAuthor = $post['author']; $postDate =…
David
  • 23
  • 1
  • 7
1 2 3
99
100