explode

PHP explode not filling in array spot 0

I have a file we will call info.txt under UNIX format that has only the following in it: #Dogs #Cats #Birds #Rabbits and am running this against it: $filename = "info.txt"; $fd = fopen ($filename, "r"); $contents = fread ($fd,filesize ($filename)); fclose ($fd); $delimiter = "#"; $insideContent = explode($delimiter, $contents); No...

Exploding a String In PHP

How do i explode this string '||25||34||73||94||116||128' i need to have a array like this array ( 0 => '25', 1 => '34', 2 => '73', 3 => '94', 4 => '116', 5 => '128' ) explode("||", $array); didnt work for me i get this array array ( 0 => '', 1 => '25', 2 => '34', 3 => '73', 4 => '94', 5 => '116', 6 => '128', ) ...

PHP output of foreach loop into a new array.

I know I'm probably missing something easy, but I have a foreach loop and I'm trying to modify the values of the first array, and output a new array with the modifications as the new values. Basically I'm starting with an array: 0 => A:B 1 => B:C 2 => C:D And I'm using explode() to strip out the :'s and second letters, so I want to ...

PHP Explode and Get_Url: Not Showing up the URL

hello! its a little bit hard to understand. in the header.php i have this code: <? $ID = $link; $url = downloadLink($ID); ?> I get the ID with this Variable $link --> 12345678 and with $url i get the full link from the functions.php in the functions.php i have this snippet function downloadlink ($d_id) { $res = @get_url ('' ...

PHP Explode: How to Download and Split a Specific HTML Part?

Hello, example: at this domain http://www.example.com/234234/go.html is only one iframe-code how can i get the url in the iframe-code? go.html: <iframe style="width: 99%;height:80%;margin:0 auto;border:1px solid grey;" src="i want this url" scrolling="auto" id="iframe_content"></iframe> i have this snippet, but its very bad coded.....

How to merge data using php.

Currently my MySQL data stored like below product | total ------------------------------------------ puma,adidas | 100.00,125.00 puma | 80.00 reebok,adidas,puma | 70.00,100.00,125.00 adidas,umbro | 125.00,56.00 How to combine, explode, merge and total it like this in php? puma ...

Make an array of two.

Hello! I'd like to make an array which tells my site's pages where to show in PHP. In $sor["site_id"] i've got two or four chars-lenght strings. example: 23, 42, 13, 1 In my other array (called to $pages_show) i want to give all the site_ids to an other id. $parancs="SELECT * FROM pages ORDER BY id"; $eredmeny=mysql_query($parancs) o...

Turn RSS into array, explode the 'description' and insert words into MySQL table one per row

I have only recently gotten into php and MySQL and I want to take an RSS feed, turn it into an array, take only the description part of the XML, explode it and insert it into a table on a MySQL base. I feel like this should be possible, but is a little over my head right now. I tried using magpie as a parser, but if possible I want to ...

PHP something faster than explode to get filename from URL

My URL's can be absolute or relative: $rel = "date/album/001.jpg"; $abs = "http://www.site.com/date/album/image.jpg"; function getFilename($url) { $imgName = explode("/", $url); $imgName = $imgName[count($imgName) - 1]; echo $imgName; } There must be a faster way to do this right? Maybe a reg expression? But that's Chines...

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 too much? ...

PHP explode and set to empty string the missing pieces

What's the best way to accomplish the following. I have strings in this format: $s1 = "name1|type1"; //(pipe is the separator) $s2 = "name2|type2"; $s3 = "name3"; //(in some of them type can be missing) Let's assume namen/typeN are strings and they can not contain a pipe. Since I need to exctract the name/type separetly, I do: $te...

Retain Delimiters when Splitting String

Edit: OK, I can't read, thanks to Col. Shrapnel for the help. If anyone comes here looking for the same thing to be answered... print_r(preg_split('/([\!|\?|\.|\!\?])/', $string, null, PREG_SPLIT_DELIM_CAPTURE)); Is there any way to split a string on a set of delimiters, and retain the position and character(s) of the delimiter after th...

PHP Question - How to create an array out of a string?

In my database, some field settings are serialized and stored. When I do this: print_r(unserialized($r['settings'])); I'll get this: Array ( [prefix] => [suffix] => [min] => [max] => [allowed_values] => 1|Common 2|Rare 3|Almost Extinct ) I'm trying to create an array based on the values for allowed_values like this: Array (...

Improve my code : Distributing the content of a textarea in two different arrays depending on markers.

Hi, I have a textarea where the user can create a feature list with a title for each block of features. The idea is to store the [title] and the features in two different MySQL tables. [Outdoor] BBQ Tennis court Swimming pool [Internal Equipment] DVD Player Plasma screen Here is what I've done so far; it works bu...

php extract value from string

I have a session variable that contains the following string. a:2:{s:7:"LoginId";s:32:"361aaeebef992bd8b57cbf390dcb3e8d";s:8:"Username";s:6:"aaaaaa";} I want to extract the value of username "aaaaaa". can anyone suggest easier/more efficient manner? $session_data = unserialize($_SESSION["SecurityAccess_CustomerAccess"]); $session_use...

How to tell explode to ignore line feeds?

I have written some small code to read in a flat text file and display it. My issue is that one of the fields has alot of text in it and also some line returns. My code is using the line return is a delimiter and moving onto the next record. How can I tell it to only split by the delimiter and ignore line returns? Sample code I am usin...

Help with exploding a name in PHP and writing back into a .CSV file

I wrote the code below to split up a fullname from a .csv file into a first name, middle name, and last name. It works well and gives the following kind of output: Eric,T.,Nolan Mary,,Worth Jim,T.,Lane E.,Thomas,Powell William,Reilly,Smith Johnny,,Depp Stevie,de,la Soul I can get it to print to the screen, but need help putting it b...

php explode new lines content from a txt file

I have txt file with email addresses under under the other like : [email protected] [email protected] So far I managed to open it with $result = file_get_contents("tmp/emails.txt"); but I don't know to to get the email addresses in an array. Basically I could use explode but how do I delimit the new line ? thanks in advance for any answer ...

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("-", $string); But how to do this when 2 delimiters are used to encapsulate the items to be e...

Explode datalist into array

Hi, I've got a list of data with in the following format: data\n data\n data\n data\n data\n Now I try to explode it into an array with $array = explode("\n", $dataList); What happens next is that there is a key with no data, I think it is because of the \n on the end. Is there a way to explode it so that the last key isn't set? ...