Re: [PHP] Split/Group date together.
Normally, what I do here is handle that in the loop to display the records ... so start by adding an order by clause to keep the dates together SELECT * FROM transportdokument WHERE dato = '16/7/2013' AND dato = '18/7/2013' order by dato $prior_date = ; $sHTML = table; while($rows = mysql_fetch_array($result)){ if ($prior_date != $rows['dato']){ if($open_table){ $sHTML .= /tabletable; $prior_date = $rows['dato']; } } $sHTML .= tr; $sHTML .= td. $rows['dato'] . /td; $sHTML .= td. $rows['some_field'] . /td; $sHTML .= td. $rows['another_field'] . /td; $sHTML .= td. $rows['third_field'] . /td; $sHTML .= /tr; } $sHTML .= /table; On Thu, Jul 18, 2013 at 9:43 AM, Karl-Arne Gjersøyen karlar...@gmail.comwrote: Hello again. In my program I have this: mysql SELECT * FROM transportdokument WHERE dato = '16/7/2013' AND dato = '18/7/2013'; This list all reccrds for 3 days. I need a way to split it up for every day even when the requst is as above and don't know in what way I can do it. I like to have all records for day 16 in one table in PHP/HTML and all records for day 17 in another table. i.e, Day 16 have 5 rows and day 17th and 18th have 7 and 8 rows. I hope for your help and advice to do also this correct. Thank you for your time and effort! Karl -- Bastien Cat, the other other white meat
Re: [PHP] Split/Group date together.
If I understand you correctly, I call what you're trying to do PHP group by, and did a write up on it a few years back: http://www.garfieldtech.com/blog/php-group-by-with-arrays --Larry Garfield On 7/18/13 8:43 AM, Karl-Arne Gjersøyen wrote: Hello again. In my program I have this: mysql SELECT * FROM transportdokument WHERE dato = '16/7/2013' AND dato = '18/7/2013'; This list all reccrds for 3 days. I need a way to split it up for every day even when the requst is as above and don't know in what way I can do it. I like to have all records for day 16 in one table in PHP/HTML and all records for day 17 in another table. i.e, Day 16 have 5 rows and day 17th and 18th have 7 and 8 rows. I hope for your help and advice to do also this correct. Thank you for your time and effort! Karl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split
On Tue, Dec 13, 2011 at 15:33, Jack jacklistm...@gmail.com wrote: OK so I have seen enough errors about split, so I decided to update my code: return split(/, $sPath, $iMax); I tried: return preg_split(/, $sPath, $iMax); return preg_split(/, $sPath, $iMax, PREG_SPLIT_DELIM_CAPTURE); and a few other combinations, in the end always with errors. not sure I get the additional aspect. I do see ther error log it tells me no ending delimiter Any help appreciated. That's because those functions use regexp strings to split. Besides, split() itself is deprecated as of 5.3. Instead, what you're looking for is explode(). Give that a try and you should be good to go. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split
Hi, First, read the help of 'preg_replace' at php.net. Second: try this: preg_split('/\//',$sPath,$iMax) Third: use explode: explode('/',) Cheers, Tamas 2011.12.13. dátummal, 21:33 időpontban Jack jacklistm...@gmail.com írta: OK so I have seen enough errors about split, so I decided to update my code: return split(/, $sPath, $iMax); I tried: return preg_split(/, $sPath, $iMax); return preg_split(/, $sPath, $iMax, PREG_SPLIT_DELIM_CAPTURE); and a few other combinations, in the end always with errors. not sure I get the additional aspect. I do see ther error log it tells me no ending delimiter Any help appreciated. Thanks! Jack -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split up Date Range
On Wednesday 01 July 2009 16:25:29 Matt Neimeyer wrote: I haven't been able to find anything by googling... Does anyone know of any libraries that will split up date ranges? We've got a project where Date Of Attendance is moving from a single type in character field to an automatically built field based on a DateBegin date field and a DateEnd date field. Some examples of what I'd like ideally... Given: July 19-22, 2009 Return: 7/19/2009 and 7/22/2009 Given: July 19th and 20th Return: 7/19/2009 and 7/20/2009 (we can safely assume current year for this project) Given: Sept 19, 2009 - Sept 22, 2009 Return: 9/19/2009 and 9/22/2009 Given: July 19th, 2009 Return: 7/19/2009 and 7/19/2009 Given: 7/19/2009 Return: 7/19/2009 and 7/19/2009 I could probably hack something together that would work most of the time... but why reinvent the wheel if some poor shlub has already done it. If such a thing doesn't exist... then I'm considering an algorithm like such... (and advice... yays and nays are appreciated) Replace the names (and variations thereof) of the months with their numeric equivilants followed by a comma. So the above would become... 7, 19-22, 2009 7, 19th and 20th 9, 19, 2009 - 9, 22, 2009 7, 19th, 2009 7/19/2009 Then replace all the th and nd and st with nothing... replace all the ands with a dash... and eliminate spaces... and change / to , Giving... 7,19-22,2009 7,19-20 9,19,2009-9,22,2009 7,19,2009 7,19,2009 Then explode on commas. If you have two elements populate the third with the current year. (This fixes 7,19-20 to 7,19-20,2009). Not a given example, but it would also fix 7/19 to 7,19,2009. When you have three elements then you have a valid date. Loop over each element and populate begin and end, if you find a dash in the current element then split on the dash and populate as needed. Yes this would allow 7-8,19-20,2009 to create 7/19/2009 and 8/20/2009 but I think its as safe as any assumption that regular people wouldn't enter that as a date range. If you have more than three elements then split on the dash and as long as you have have only two elements then consider each item by itself. If it's not handled by the above rules then don't split it up. Thanks in advance. Matt Wow, first question is, why accept such a variety of inputs? Can't you force a particular standard for people that allows them to enter a range? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split up Date Range
It would be easier to standardize the input so you only have to run one regular expression check to validate and then split the data up. On Wed, Jul 1, 2009 at 10:33 AM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: On Wednesday 01 July 2009 16:25:29 Matt Neimeyer wrote: I haven't been able to find anything by googling... Does anyone know of any libraries that will split up date ranges? We've got a project where Date Of Attendance is moving from a single type in character field to an automatically built field based on a DateBegin date field and a DateEnd date field. Some examples of what I'd like ideally... Given: July 19-22, 2009 Return: 7/19/2009 and 7/22/2009 Given: July 19th and 20th Return: 7/19/2009 and 7/20/2009 (we can safely assume current year for this project) Given: Sept 19, 2009 - Sept 22, 2009 Return: 9/19/2009 and 9/22/2009 Given: July 19th, 2009 Return: 7/19/2009 and 7/19/2009 Given: 7/19/2009 Return: 7/19/2009 and 7/19/2009 I could probably hack something together that would work most of the time... but why reinvent the wheel if some poor shlub has already done it. If such a thing doesn't exist... then I'm considering an algorithm like such... (and advice... yays and nays are appreciated) Replace the names (and variations thereof) of the months with their numeric equivilants followed by a comma. So the above would become... 7, 19-22, 2009 7, 19th and 20th 9, 19, 2009 - 9, 22, 2009 7, 19th, 2009 7/19/2009 Then replace all the th and nd and st with nothing... replace all the ands with a dash... and eliminate spaces... and change / to , Giving... 7,19-22,2009 7,19-20 9,19,2009-9,22,2009 7,19,2009 7,19,2009 Then explode on commas. If you have two elements populate the third with the current year. (This fixes 7,19-20 to 7,19-20,2009). Not a given example, but it would also fix 7/19 to 7,19,2009. When you have three elements then you have a valid date. Loop over each element and populate begin and end, if you find a dash in the current element then split on the dash and populate as needed. Yes this would allow 7-8,19-20,2009 to create 7/19/2009 and 8/20/2009 but I think its as safe as any assumption that regular people wouldn't enter that as a date range. If you have more than three elements then split on the dash and as long as you have have only two elements then consider each item by itself. If it's not handled by the above rules then don't split it up. Thanks in advance. Matt Wow, first question is, why accept such a variety of inputs? Can't you force a particular standard for people that allows them to enter a range? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- - Adam Shannon ( http://ashannon.us )
Re: [PHP] split in to multiple pages ( pagination)
In news: [EMAIL PROTECTED] - Greg Donald wrote : On Sat, 15 Sep 2007, Joker7 wrote: I'm using the code below to display news articles-which works great apart from. I can control the number of articles,but I would like to add a link to the bottom of the page to the un-displayed articles ( nexted 5 articles and so on) any pointers would be most welcome as most know my PHP skills are not the best :). ? $max_latest = 5; $filename = articlesum.php; #- open article if(file_exists($filename)){ $fh = fopen($filename, r); $old_news = fread($fh, filesize($filename)); fclose($fh); } #- get article $articles = explode(!--ARTICLE--, $old_news); $i=0; foreach ( $articles as $article ){ if(count($articles)$i){ if($max_latest = $i++){ print $article; } } } There's a bunch of how-tos and discussion on this topic already: http://google.com/search?q=php+pagination You have to manage a variable across page requests to keep track of where you are. Use that variable in your SQL as part of your offset/limit parameters. -- Greg Donald Cyberfusion Consulting http://cyberfusionconsulting.com/ Thanks for the reply - I now know what it's called :) I forgot to and it's a flat file system not the best but is ok for my needs. I spent a couple of hours following link from google an not a sausage on flat files :( Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split in to multiple pages (I think)
On Sat, 15 Sep 2007, Joker7 wrote: I'm using the code below to display news articles-which works great apart from. I can control the number of articles,but I would like to add a link to the bottom of the page to the un-displayed articles ( nexted 5 articles and so on) any pointers would be most welcome as most know my PHP skills are not the best :). There's a bunch of how-tos and discussion on this topic already: http://google.com/search?q=php+pagination You have to manage a variable across page requests to keep track of where you are. Use that variable in your SQL as part of your offset/limit parameters. -- Greg Donald Cyberfusion Consulting http://cyberfusionconsulting.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
Lester Caine skrev: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. $myString = John Doe; $pos = strpos($myString, ) strpos($myString, ,) ? strpos($myString, ) : strpos($myString, ,); $part1 = substr($myString, 0, $pos); $part2 = substr($myString, $pos); /T -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
Fredrik Thunberg wrote: Lester Caine skrev: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. $myString = John Doe; $pos = strpos($myString, ) strpos($myString, ,) ? strpos($myString, ) : strpos($myString, ,); $part1 = substr($myString, 0, $pos); $part2 = substr($myString, $pos); I'm glad I asked now, that is a lot nicer than trying to get the preg_split thing working :) -- Lester Caine - G8HFL - Contact - http://home.lsces.co.uk/lsces/wiki/?page=contact L.S.Caine Electronic Services - http://home.lsces.co.uk MEDW - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/ Firebird Foundation Inc. - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
Fredrik Thunberg wrote: Lester Caine skrev: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. $myString = John Doe; $pos = strpos($myString, ) strpos($myString, ,) ? strpos($myString, ) : strpos($myString, ,); Suggest the following as being more efficient (half the strpos calls)... $pos = min(strpos($myString, ), strpos($myString, ,)); Alternatively you could use split to break the string into the two parts, which is probably more efficient... list($part1, $part2) = split('[ ,]', $myString); -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
Stut wrote: Alternatively you could use split to break the string into the two parts, which is probably more efficient... list($part1, $part2) = split('[ ,]', $myString); Oops, this should have a third parameter... list($part1, $part2) = split('[ ,]', $myString, 2); -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
On Wed, May 2, 2007 3:55 am, Lester Caine wrote: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. One of these should have an example to get you where you need to be: http://php.net/split http://php.net/preg_split -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
On Wed, May 2, 2007 4:55 am, Lester Caine wrote: Fredrik Thunberg wrote: Lester Caine skrev: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. $myString = John Doe; $pos = strpos($myString, ) strpos($myString, ,) ? strpos($myString, ) : strpos($myString, ,); $part1 = substr($myString, 0, $pos); $part2 = substr($myString, $pos); I'm glad I asked now, that is a lot nicer than trying to get the preg_split thing working :) Hnmmm. Okay, I'll take a shot at it: $answer = preg_split('|[, ]|', $myString); var_dump($answer); -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
Richard Lynch wrote: On Wed, May 2, 2007 4:55 am, Lester Caine wrote: Fredrik Thunberg wrote: Lester Caine skrev: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. $myString = John Doe; $pos = strpos($myString, ) strpos($myString, ,) ? strpos($myString, ) : strpos($myString, ,); $part1 = substr($myString, 0, $pos); $part2 = substr($myString, $pos); I'm glad I asked now, that is a lot nicer than trying to get the preg_split thing working :) Hnmmm. Okay, I'll take a shot at it: $answer = preg_split('|[, ]|', $myString); var_dump($answer); Will give more than 2 parts for strings containing both or multiples. Now please irradiate your hands. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
Stut wrote: Richard Lynch wrote: On Wed, May 2, 2007 4:55 am, Lester Caine wrote: Fredrik Thunberg wrote: Lester Caine skrev: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. $myString = John Doe; $pos = strpos($myString, ) strpos($myString, ,) ? strpos($myString, ) : strpos($myString, ,); $part1 = substr($myString, 0, $pos); $part2 = substr($myString, $pos); I'm glad I asked now, that is a lot nicer than trying to get the preg_split thing working :) Hnmmm. Okay, I'll take a shot at it: $answer = preg_split('|[, ]|', $myString); var_dump($answer); Will give more than 2 parts for strings containing both or multiples. Now please irradiate your hands. -Stut This should work for you. ?php $myString = Here is my first, attempt!; $answer = preg_split('|[, ]|', $myString, 2); var_dump($answer); ? -- Enjoy, Jim Lucas Different eyes see different things. Different hearts beat on different strings. But there are times for you and me when all such things agree. - Rush -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
On May 2, 2007, at 4:10 PM, Stut wrote: Richard Lynch wrote: On Wed, May 2, 2007 4:55 am, Lester Caine wrote: Fredrik Thunberg wrote: Lester Caine skrev: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. $myString = John Doe; $pos = strpos($myString, ) strpos($myString, ,) ? strpos($myString, ) : strpos($myString, ,); $part1 = substr($myString, 0, $pos); $part2 = substr($myString, $pos); I'm glad I asked now, that is a lot nicer than trying to get the preg_split thing working :) Hnmmm. Okay, I'll take a shot at it: $answer = preg_split('|[, ]|', $myString); var_dump($answer); Will give more than 2 parts for strings containing both or multiples. Now please irradiate your hands. This won't: $answer = preg_split('/(?:,|\s)+/', $myString); At least not in my tests. Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
On Wed, May 2, 2007 4:10 pm, Stut wrote: Richard Lynch wrote: On Wed, May 2, 2007 4:55 am, Lester Caine wrote: Fredrik Thunberg wrote: Lester Caine skrev: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. $myString = John Doe; $pos = strpos($myString, ) strpos($myString, ,) ? strpos($myString, ) : strpos($myString, ,); $part1 = substr($myString, 0, $pos); $part2 = substr($myString, $pos); I'm glad I asked now, that is a lot nicer than trying to get the preg_split thing working :) Hnmmm. Okay, I'll take a shot at it: $answer = preg_split('|[, ]|', $myString); var_dump($answer); Will give more than 2 parts for strings containing both or multiples. Yeah, I definitely missed the limit 2 requirement when I read through the OP. Though I don't think the 2 bit was the tricky part of the PREG... :-) Now please irradiate your hands. I think they had that done to them way back when, and that's why I post so much... You want me to do it again? :-) -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
Jim Lucas wrote: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( This should work for you. $myString = Here is my first, attempt!; $answer = preg_split('|[, ]|', $myString, 2); Ok having re-read the preg_split manual page and now found a nice crib sheet for 'pattern' I can understand that. Although it is not obvious from the manual what gets returned if there are two comma's or spaces. I would have expected I think that everything after the second match would be lost? As you only asked to return the first 2 strings, but the last string does contain all the remaining characters :) ( There is a note about it in the comments, but it would be nice to include that sort of fine detail in the main explanation. I've already found the other problem with this simple search selection. Originally I just wanted to do Jones,A and the above would work fine. But some customers said 'We are used to Jones A in X - can you do that'. Of cause anything is possible in software, hence the original question, except where they have actually typed 'JONES A' as the Surname ;) -- Lester Caine - G8HFL - Contact - http://home.lsces.co.uk/lsces/wiki/?page=contact L.S.Caine Electronic Services - http://home.lsces.co.uk MEDW - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/ Firebird Foundation Inc. - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ? Split string into smaller chunks
[snip] I need to split a long string into smaler chunks (an array), as a separator using every third \n (and not just every \n). I could use 'explode', but then it would produce too many chunks. [/snip] http://us2.php.net/manual/en/function.chunk-split.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ? Split string into smaller chunks
Split them using explode and then combine the ones you need to combined. Hope this helps. -- Anas Mughal On 12/19/05, Labunski [EMAIL PROTECTED] wrote: I need to split a long string into smaler chunks (an array), as a separator using every third \n (and not just every \n). I could use 'explode', but then it would produce too many chunks. Thank you in advance! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Anas Mughal
Re: [PHP] ? Split string into smaller chunks
Labunski wrote: I need to split a long string into smaler chunks (an array), as a separator using every third \n (and not just every \n). I could use 'explode', but then it would produce too many chunks. php.net/preg_split Cheers, David -- David Grant http://www.grant.org.uk/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split or explode quoted strings
Ördögh László wrote: I would like to split or explode strings in a way that quoted strings inside the strings should remain. e.g.: first second \third third\ fourth \fifth fifth fifth\ after the split I need: first second third third fourth fifth fifth fifth I love explode(), too, but this is a job for sscanf(): http://php.net/sscanf Hope that helps. Chris -- Chris Shiflett Brain Bulb, The PHP Consultancy http://brainbulb.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split or explode quoted strings
On 11/14/05, Ördögh László [EMAIL PROTECTED] wrote: Hello, I would like to split or explode strings in a way that quoted strings inside the strings should remain. e.g.: first second \third third\ fourth \fifth fifth fifth\ after the split I need: first second third third fourth fifth fifth fifth How about something like this? ?php $singleQuoted = (?:'(?:[^']|.)*'); $doubleQuoted = '(?:(?:[^]|.)*)'; $re = /$singleQuoted|$doubleQuoted|\S+/s; preg_match_all($re, $text, $quotedWords); print_r($quotedWords); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split line of text
if chunk_split function split the line of text (here on 50 char) I was wondering if there exists one function who take care if the 50 char is in the middle of the word and split the line first empty space before the word or just after? $newstring = chunk_split($row[1], 50, 'br /'); echo $newstring; http://us3.php.net/manual/en/function.wordwrap.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split line of text
Le 27-sept.-05 à 23:52, Philip Hallstrom a écrit : http://us3.php.net/manual/en/function.wordwrap.php thanks a lot! $newtext = wordwrap($row[1], 50, br /\n); echo $newtext; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split()?
Here is one way to do it: $rr=thisscritjajsj[ OUT1 ]ajdamsda;sjo;tkpdk[ OUT2 ]sdfmjs[ OUT3 ]dfjlsd; preg_match(/.*\[(.*)\].*\[(.*)\].*\[(.*)\].*/, $rr, $match); list($whole_match[],$a[],$a[],$a[]) = $match; print pre; print_r ($a); print /pre; exit; Mark Cain - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, June 14, 2005 8:13 PM Subject: [PHP] split()? How would I do this ? Take this string and return everything between [ ] as an array output doesnt have to inlude [ ] $rr=thisscritjajsj[ OUT1 ]ajdamsda;sjo;tkpdk[ OUT2 ]sdfmjs[ OUT3 ]dfjlsd; $a = some function echo 'pre'; print_r($a); [0] = [ OUT1 ] [1] = [ OUT2 ] [2] = [ OUT3 ] Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split()?
* Mark Cain [EMAIL PROTECTED] : Here is one way to do it: $rr=thisscritjajsj[ OUT1 ]ajdamsda;sjo;tkpdk[ OUT2 ]sdfmjs[ OUT3 ]dfjlsd; preg_match(/.*\[(.*)\].*\[(.*)\].*\[(.*)\].*/, $rr, $match); list($whole_match[],$a[],$a[],$a[]) = $match; This is fine as long as there's precisely three escape sequences in the string; if there's an arbitrary number, that won't work. I've posted another solution already using preg_match_all() that will. - Original Message - From: [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, June 14, 2005 8:13 PM Subject: [PHP] split()? How would I do this ? Take this string and return everything between [ ] as an array output doesnt have to inlude [ ] $rr=thisscritjajsj[ OUT1 ]ajdamsda;sjo;tkpdk[ OUT2 ]sdfmjs[ OUT3 ]dfjlsd; $a = some function echo 'pre '; print_r($a); [0] = [ OUT1 ] [1] = [ OUT2 ] [2] = [ OUT3 ] -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split command problem
On Monday 11 April 2005 09:27, Russ wrote: I have been trying to get the following code working. I keep getting an error on line nine. And the error is? It looks simular to the example in the PHP online manual. If I substitute a print command for line nine I get the correct information from $_POST[username]. I must be missing or have an extra a quote but I cannot figure out where. name($fname, $lname) = split('[/\s+/]', $_POST[username]); split() probably uses POSIX regex and hence knows nothing about '\s'. Use preg_split() instead: list($fname, $lname) = preg_split('/\s+/', $_POST['username']); -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- New Year Resolution: Ignore top posted posts -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split command problem
I guess you are trying to create an array by the name 'name' and assign two elements to it by calling name($fname, $lname). Am I correct? I think it does not work that way. Try list($fname, $lname) = .. Then the variable $fname and $lname will contain the first and last names. list($fname, $lname) = split('[/\s+/]', $_POST[username]); Cheers, Prathap -- Original Message --- From: Russ [EMAIL PROTECTED] To: PHP General php-general@lists.php.net Sent: Sun, 10 Apr 2005 18:27:34 -0700 Subject: [PHP] Split command problem I have been trying to get the following code working. I keep getting an error on line nine. It looks simular to the example in the PHP online manual. If I substitute a print command for line nine I get the correct information from $_POST[username]. I must be missing or have an extra a quote but I cannot figure out where. ?php //check for required fields from the form if ((!$_POST[username]) || (!$_POST[password])) { header(Location: memberlogin15.7.php); exit; } if(preg_match(/[A-Z]/, substr($_POST[username], 0, 1))) { name($fname, $lname) = split('[/\s+/]', $_POST[username]); //echo First Name: $fname; Last Name: $lname\n; echo first letter is uppercase; } else { echo first letter is not uppercase; } Any help will be appreciated. -- Russ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- End of Original Message --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split command problem
On Apr 10, 2005 8:27 PM, Russ [EMAIL PROTECTED] wrote: I have been trying to get the following code working. I keep getting an error on line nine. It looks simular to the example in the PHP online manual. If I substitute a print command for line nine I get the correct information from $_POST[username]. I must be missing or have an extra a quote but I cannot figure out where. ?php //check for required fields from the form if ((!$_POST[username]) || (!$_POST[password])) { header(Location: memberlogin15.7.php); exit; } if(preg_match(/[A-Z]/, substr($_POST[username], 0, 1))) { name($fname, $lname) = split('[/\s+/]', $_POST[username]); Where is your 'name' function and what does it do? I'd do: $name = explode( ' ', $_POST[ 'username' ] ); echo First Name: $name[0] Last Name: $name[1]; //echo First Name: $fname; Last Name: $lname\n; echo first letter is uppercase; } else { echo first letter is not uppercase; } -- Greg Donald Zend Certified Engineer http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split haystack at nth occurrence of needle?
I've been RTFMing for about an hour and I can't find a string function to split haystack 'onebrtwobrthreebrfourbrfive' at the nth occurrence of needle 'br'. strpos gives me the position of the first needle, and strrpos gives me the position of the last needle. But I'm looking for the position of one of the in-between needles, so that I can use substr() to trim everything from there on. What very obvious function was I unable to find in the manual? You could use explode(). ? $string = 'onebrtwobrthreebrfourbrfive'; $nthPos = 4; $tmpArr = explode( 'br', $string ); $nthString = $tmpArr[($nthPos - 1)]; ? Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split haystack at nth occurrence of needle?
? $string = 'onebrtwobrthreebrfourbrfive'; $nthPos = 4; $tmpArr = explode( 'br', $string ); $nthString = $tmpArr[($nthPos - 1)]; ? Thanks Chris, that works great, but it's not doing what I want. I'm just trying to get the position of the 3rd occurrence (for example) of 'br'. So I'm looking for a function that will return the value 19, given the above example string. - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split haystack at nth occurrence of needle?
Hi if you want the *rest of the string from the nth br*, I think 'preg_match_all' with PREG_OFFSET_CAPTURE can help you (see http://www.php.net/manual/en/function.preg-match-all.php) You could do something like: code $string = onebrtwobrthreebrfourbrfive; $count = preg_match_all('/br([^]+)/', $string, $out, PREG_OFFSET_CAPTURE); /code and you will have an array of 2 arrays, where the first one contains the full pattern matches and the second one contains arrays for each string matched *and the starting offset* of that string. Therefore, to know where the 2nd br ends (so we would get 'three') all you have to do is: $out[1][1][1] = 14 Just my .2 euros... Silvio Porcellana - Original Message - From: Brian Dunning [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 22, 2004 5:54 PM Subject: [PHP] Split haystack at nth occurrence of needle? I've been RTFMing for about an hour and I can't find a string function to split haystack 'onebrtwobrthreebrfourbrfive' at the nth occurrence of needle 'br'. strpos gives me the position of the first needle, and strrpos gives me the position of the last needle. But I'm looking for the position of one of the in-between needles, so that I can use substr() to trim everything from there on. What very obvious function was I unable to find in the manual? Thanks, - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split haystack at nth occurrence of needle?
On Wed, 2004-09-22 at 12:31, Brian Dunning wrote: ? $string = 'onebrtwobrthreebrfourbrfive'; $nthPos = 4; $tmpArr = explode( 'br', $string ); $nthString = $tmpArr[($nthPos - 1)]; ? Thanks Chris, that works great, but it's not doing what I want. I'm just trying to get the position of the 3rd occurrence (for example) of 'br'. So I'm looking for a function that will return the value 19, given the above example string. The following should get you going: function strpos_nth( $hay, $needle, $n=1 ) { $offset = -1; if( $n 1 ) { return false; } while( $n-- 0 ) { if( ($offset = strpos( $hay, $needle, $offset + 1 )) === false ) { return false; } } return $offset; } Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split haystack at nth occurrence of needle?
Brian Dunning wrote: Thanks Chris, that works great, but it's not doing what I want. I'm just trying to get the position of the 3rd occurrence (for example) of 'br'. So I'm looking for a function that will return the value 19, given the above example string. From your first post, you just want to remove everything after a certain occurrence. I don't understand why explode won't work for you. As in, ? $string = 'onebrtwobrthreebrfourbrfive'; $nthPos = 4; $tmpArr = explode( 'br', $string ); $newArr = array_slice($tmpArr,0,$nthPos-1); $shortString = implode('br',$newArr); ? A function that would give you the position to truncate from would be shorter. But, I don't seem to be finding that function either. So, the above seems like a solution. Janet - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split haystack at nth occurrence of needle?
I don't understand why explode won't work for you. The explode solution is working. Thanks very much to everyone who replied with so much great information! - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split haystack at nth occurrence of needle?
* Thus wrote Janet Valade: Brian Dunning wrote: Thanks Chris, that works great, but it's not doing what I want. I'm just trying to get the position of the 3rd occurrence (for example) of 'br'. So I'm looking for a function that will return the value 19, given the above example string. From your first post, you just want to remove everything after a certain occurrence. I don't understand why explode won't work for you. As in, ? $string = 'onebrtwobrthreebrfourbrfive'; $nthPos = 4; $tmpArr = explode( 'br', $string ); $newArr = array_slice($tmpArr,0,$nthPos-1); $shortString = implode('br',$newArr); and the short version: $shortString = implode('br', explode('br', $string, $nth)); Curt -- The above comments may offend you. flame at will. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split haystack at nth occurrence of needle?
* Thus wrote Curt Zirzow: $shortString = implode('br', explode('br', $string, $nth)); ignore this. Curt -- The above comments may offend you. flame at will. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split behaviour differences in perl and php
Sandip Bhattacharya wrote: This stumped me badly in my present project. Is this a bug or a feature in PHP? I am trying to split a string into two, where only one half (and the delimiter) is present. [ trim ] IN PHP === [EMAIL PROTECTED] ~]$ cat s1.php ?php print count(split(',', 'a,b')).\n; print count(split(',', 'a,')).\n; ? [EMAIL PROTECTED] sql]$ php -q s1.php 2 2 If your expand your example slightly, as I did, you will see why you are getting the expected results: [EMAIL PROTECTED] burhan $ cat s1.php ?php $results = split(',', 'a,b'); print_r($results); print count($results).\n; $results = split(',','a,'); print_r($results); print count($results).\n; ? [EMAIL PROTECTED] burhan $ php -q s1.php Array ( [0] = a [1] = b ) 2 Array ( [0] = a [1] = ) 2 As you can see, the array contains an empty second element because (correctly) there isn't a second element after the last ,. So, is this a bug? Not from my point of view. Its more bad input, expected result :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split behaviour differences in perl and php
* Thus wrote Sandip Bhattacharya: This stumped me badly in my present project. Is this a bug or a feature in PHP? I am trying to split a string into two, where only one half (and the delimiter) is present. IN PERL == [EMAIL PROTECTED] ~]$ cat s1.pl @t = split(/,/ , a,b); $len = $#t + 1; print $len\n; @t = split(/,/, a,); $len = $#t + 1; print $len\n; [EMAIL PROTECTED] sql]$ perl s1.pl 2 1 IN PHP === [EMAIL PROTECTED] ~]$ cat s1.php ?php print count(split(',', 'a,b')).\n; print count(split(',', 'a,')).\n; ? [EMAIL PROTECTED] sql]$ php -q s1.php 2 2 split in php isn't the same as perl's split, there is preg_split() which you can use: $results = preg_split('/,/','a,', -1, PREG_SPLIT_NO_EMPTY); print(count($results)); // outputs: 1 Curt -- The above comments may offend you. flame at will. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] split behaviour differences in perl and php
PHP's string manipulation functions (such as split()) are not guaranteed to behave exactly like in PERL. The functions that are prefixed by 'preg_' are (PERL REG (EX)) guaranteed to some extent and well documented where preg_ functions are not PERL compliant. So, its not a bug, its just PHP being its own language. Cheers, Andrew Martinez RubyBay Inc. -Original Message- From: Curt Zirzow [mailto:[EMAIL PROTECTED] Sent: Thursday, September 16, 2004 10:45 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] split behaviour differences in perl and php * Thus wrote Sandip Bhattacharya: This stumped me badly in my present project. Is this a bug or a feature in PHP? I am trying to split a string into two, where only one half (and the delimiter) is present. IN PERL == [EMAIL PROTECTED] ~]$ cat s1.pl @t = split(/,/ , a,b); $len = $#t + 1; print $len\n; @t = split(/,/, a,); $len = $#t + 1; print $len\n; [EMAIL PROTECTED] sql]$ perl s1.pl 2 1 IN PHP === [EMAIL PROTECTED] ~]$ cat s1.php ?php print count(split(',', 'a,b')).\n; print count(split(',', 'a,')).\n; ? [EMAIL PROTECTED] sql]$ php -q s1.php 2 2 split in php isn't the same as perl's split, there is preg_split() which you can use: $results = preg_split('/,/','a,', -1, PREG_SPLIT_NO_EMPTY); print(count($results)); // outputs: 1 Curt -- The above comments may offend you. flame at will. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split behaviour differences in perl and php
* Thus wrote Sandip Bhattacharya: This stumped me badly in my present project. Is this a bug or a feature in PHP? I am trying to split a string into two, where only one half (and the delimiter) is present. IN PERL == [EMAIL PROTECTED] ~]$ cat s1.pl @t = split(/,/ , a,b); $len = $#t + 1; print $len\n; @t = split(/,/, a,); $len = $#t + 1; print $len\n; [EMAIL PROTECTED] sql]$ perl s1.pl 2 1 IN PHP === [EMAIL PROTECTED] ~]$ cat s1.php ?php print count(split(',', 'a,b')).\n; print count(split(',', 'a,')).\n; ? [EMAIL PROTECTED] sql]$ php -q s1.php 2 2 split in php isn't the same as perl's split, there is preg_split() which you can use: $results = preg_split('/,/','a,', -1, PREG_SPLIT_NO_EMPTY); print(count($results)); // outputs: 1 Curt Would explode() provide the same technique? $var = a,; $results = explode(,, $var); $results[0] = a; -- --Matthew Sims --http://killermookie.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split()
On Tue, 2004-02-17 at 11:03, John Taylor-Johnston wrote: Can I while this? Not sure how to go about it? $pizza = piece1 piece2 piece3 piece4 piece5 piece6; $pieces = explode( , $pizza); echo $pieces[0]; // piece1 echo $pieces[1]; // piece2 Try while(each($pieces)) or foreach($pieces as $piece) -- Adam Bregenzer [EMAIL PROTECTED] http://adam.bregenzer.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split()
John Taylor-Johnston wrote: Can I while this? Not sure how to go about it? while ($pieces exist) { echo $pieces[i]; } This will empty the array so you might want to do this on a copy of it depending on whether it will be needed later in the script... while (count($pieces) 0) { echo array_shift($pieces); } http://php.net/array_shift -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split()
On Tue, 2004-02-17 at 11:02, Adam Bregenzer wrote: Try while(each($pieces)) or foreach($pieces as $piece) Brain to fingers problem: while($piece = each($pieces)) http://www.php.net/each http://www.php.net/foreach -- Adam Bregenzer [EMAIL PROTECTED] http://adam.bregenzer.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split()
save a function call: $applePie = array(1,2,3,4,5,6,7,8); while ($pieceOfPie = array_shift($applePie)) { echo $pieceOfPie; // want some pie? } Stuart wrote: John Taylor-Johnston wrote: Can I while this? Not sure how to go about it? while ($pieces exist) { echo $pieces[i]; } This will empty the array so you might want to do this on a copy of it depending on whether it will be needed later in the script... while (count($pieces) 0) { echo array_shift($pieces); } http://php.net/array_shift -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split()
On Tue, 2004-02-17 at 15:22, Jochem Maas wrote: $applePie = array(1,2,3,4,5,6,7,8); while ($pieceOfPie = array_shift($applePie)) { echo $pieceOfPie; // want some pie? } Careful, that will eat your array as well. When the while loop finishes you won't have any pieces of pie left! IE: $applePie = array(1,2,3,4,5,6,7,8); while ($pieceOfPie = array_shift($applePie)) { echo $pieceOfPie; // want some pie? } // Both of these are now true: $applePie == array(); $applePie != array(1,2,3,4,5,6,7,8); -Adam -- Adam Bregenzer [EMAIL PROTECTED] http://adam.bregenzer.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split()
Adam Bregenzer wrote: On Tue, 2004-02-17 at 15:22, Jochem Maas wrote: $applePie = array(1,2,3,4,5,6,7,8); while ($pieceOfPie = array_shift($applePie)) { echo $pieceOfPie; // want some pie? } Careful, that will eat your array as well. When the while loop finishes you won't have any pieces of pie left! that was the idea: you can't have your pie at eat it right? ;-) seriously thought, John Taylor-Johnston was asking for help on while loops and I thought I'd give him some brainfood (i.e. a little optimalization thrown in). besides which how many times have we in our PHP careers not created arrays just to loop over them once, outputting each item? IE: $applePie = array(1,2,3,4,5,6,7,8); while ($pieceOfPie = array_shift($applePie)) { echo $pieceOfPie; // want some pie? } // Both of these are now true: $applePie == array(); $applePie != array(1,2,3,4,5,6,7,8); -Adam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split()
On Tue, 2004-02-17 at 22:28, Jochem Maas wrote: that was the idea: you can't have your pie at eat it right? ;-) Heh, I thought you might have done that deliberately. :) seriously thought, John Taylor-Johnston was asking for help on while loops and I thought I'd give him some brainfood (i.e. a little optimalization thrown in). besides which how many times have we in our PHP careers not created arrays just to loop over them once, outputting each item? Oh yeah, that's one side effect of PHP, you completely forget about: memory and garbage collection concerns. -- Adam Bregenzer [EMAIL PROTECTED] http://adam.bregenzer.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split()
On Wed, Nov 12, 2003 at 09:48:37PM -0600, erythros wrote: : : trying to use split(). i want to split a paragraph by sentence. so of course : i used split('[.!?]', $data). but then i noticed i use ... or every now : and again at the end of a sentence. i don't know how to do this though... How about preg_split('[.!?]+', $data) ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split()
thanx for the help. i got it. when i saw what happened when i put the + at the end i found what i needed. split('[.!?] ', $data) this way it only breaks them up if the . or ! or ? is followed by a space. thanx again for the help. Eugene Lee [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Wed, Nov 12, 2003 at 09:48:37PM -0600, erythros wrote: : : trying to use split(). i want to split a paragraph by sentence. so of course : i used split('[.!?]', $data). but then i noticed i use ... or every now : and again at the end of a sentence. i don't know how to do this though... How about preg_split('[.!?]+', $data) ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split()
--- erythros [EMAIL PROTECTED] wrote: trying to use split(). i want to split a paragraph by sentence. so of course i used split('[.!?]', $data). but then i noticed i use ... or every now and again at the end of a sentence. Maybe you could explode on a period followed by a space? I wouldn't think split is necessary here. Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split ...
From: Dan Joseph [EMAIL PROTECTED] I'm getting the following error: [Tue Nov 4 10:01:53 2003] [error] PHP Warning: split() [a href='http://www.php.net/function.split'function.split/a]: REG_EMPTY in /usr/local/apache/htdocs-chm/import_data.php on line 26 Here is the code in question: $line = fgets( $file ); echo $line . br; list ( $ACTION_DESCR, $LOAN_NUMBER, $BORROWER, $CO_BORROWER, $ADDRESS, $CITY, $STATE, $ZIP, $ABANUM, $BANKACCTTYPE, $BANKACCTNUM, $ADD_PRINCIPAL, $DAYS_TRANSFER, $FILE_NAME, $DATE_CREATED ) = split( |, $line ); The | character is a special character in regular expressions, which split() expects. So, you can use split(\|,$line) which escapes the | character. Although, since you're not really using a regular expression, you'd be better off (more efficient) to just use explode('|',$line) and have the same effect. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] split ...
Hi, Thanks, that worked like a charm. I didn't realize that | was a special character, that's good to know. I also agree with the explode method. Seems quicker. Thanks! -Dan Joseph The | character is a special character in regular expressions, which split() expects. So, you can use split(\|,$line) which escapes the | character. Although, since you're not really using a regular expression, you'd be better off (more efficient) to just use explode('|',$line) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] split
On 27-Mar-2003 Oden Odenius wrote: I have $word = test; And i want to split it like t e s t I want to make a loop.Like $a = 123; //$a is One two threw not hundred... and i want to make for each $a then $b = $a + 2 The output will be. 3 (1+2) 4 (2+2) 5 (3+2) Any example? $str='test'; $ary=preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY); echo implode(br\n, $ary), 'P'; $ary=preg_split('//', '123', -1, PREG_SPLIT_NO_EMPTY); foreach($ary as $a) { $b= $a + 2; echo br, $b, nbsp; ($a + 2); } Btw sorry for my english -- Programmers are tools for convert coffeine into code... (c) Oden _ MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. (53kr33t w0rdz: sql table query) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split
This: $word = 'test'; $len = strlen($word); for ($a = 0; $a $len; $a++) { print $word{$a} . \n; } Will print: t e s t Regards, Philip On Thu, 27 Mar 2003, Oden Odenius wrote: I have $word = test; And i want to split it like t e s t I want to make a loop.Like $a = 123; //$a is One two threw not hundred... and i want to make for each $a then $b = $a + 2 The output will be. 3 (1+2) 4 (2+2) 5 (3+2) Any example? Btw sorry for my english -- Programmers are tools for convert coffeine into code... (c) Oden _ MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] split
I want to make a loop.Like $a = 123; //$a is One two threw not hundred... and i want to make for each $a then $b = $a + 2 The output will be. 3 (1+2) 4 (2+2) 5 (3+2) Any example? $a = 123; $c = ''; $b = strlen($a); for($x=0;$x$b;$x++) { $c .= $a{$x} +2; } echo $c; ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split() - not working in this case
? function split_addresses($addr) { $ad = array(); $ad = split(,,$addr); return $ad; } $tos=array(); $to = abcd [EMAIL PROTECTED], efgh [EMAIL PROTECTED]; $tos=split_addresses($to); echo $tos[1]; ? echos efgh [EMAIL PROTECTED] ?? Whats the problem? Maybe you output to a browser and don't see [EMAIL PROTECTED] cause its between Op zondag 08 september 2002 10:17, schreef N. Pari Purna Chand: I have a string $to = abcd [EMAIL PROTECTED], efgh [EMAIL PROTECTED] ; I want a function returning an array of indivial names+mailids like from the $to seperated by , something like $tos[0] = abcd [EMAIL PROTECTED]; $tos[1] = efgh [EMAIL PROTECTED]; Now split() in the following function*** is notworking as needed. ie, I'm getting $tos[0] = abcd; $tos[1] = efgh; Not the complete name + mailid, Why ? /Chandu *** function split_addresses($addr) { $ad = array(); $ad = split(,,$addr); return $ad; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split() - not working in this case
On Sun, 8 Sep 2002, N. Pari Purna Chand wrote: $to = abcd [EMAIL PROTECTED], efgh [EMAIL PROTECTED] ; Now split() in the following function*** is notworking as needed. ie, I'm getting $tos[0] = abcd; $tos[1] = efgh; split didn't do anything wrong. use your browser's view source to see the desired output. funny things, those less-than greater-than characters ... they make browsers think you've created an HTML tag! Two things you can do to make displaying such data in a browser: 1) if you're trying to display text that has HTML entities in it, within a HTML page, use the htmlentities() function when printing output. http://www.php.net/htmlentities 2) if you don't care about HTML at all, send a Content-type header that tells the browser what you're sending is text. header( Content-type: text/plain ); g.luck, ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] split() - not working in this case
Yeah, I have outputted to browser Split() was working fine.. Sorry for the noise on the list. But I have realised that the very moment I posted the mail on the list. /Chandu - Original Message - From: Chris Wesley [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: N. Pari Purna Chand [EMAIL PROTECTED] Sent: Sunday, September 08, 2002 2:33 PM Subject: Re: [PHP] split() - not working in this case On Sun, 8 Sep 2002, N. Pari Purna Chand wrote: $to = abcd [EMAIL PROTECTED], efgh [EMAIL PROTECTED] ; Now split() in the following function*** is notworking as needed. ie, I'm getting $tos[0] = abcd; $tos[1] = efgh; split didn't do anything wrong. use your browser's view source to see the desired output. funny things, those less-than greater-than characters ... they make browsers think you've created an HTML tag! Two things you can do to make displaying such data in a browser: 1) if you're trying to display text that has HTML entities in it, within a HTML page, use the htmlentities() function when printing output. http://www.php.net/htmlentities 2) if you don't care about HTML at all, send a Content-type header that tells the browser what you're sending is text. header( Content-type: text/plain ); g.luck, ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split files
Making any sense? Year, so I have to do it manually (thought someone could preveting me from reinvent the wheel... ;-) What are you really trying to achieve? I'm trying to split a large binary file (2 GB) into peaces of 700 MB to burn it on a cd. It's a part of a backup-mechanism I'm wirting in PHP. Maybe you could find a program that will do the split for you then call that from within PHP. =Hmm, I'm still come at it from the other way around (all due respect to Jason) - but then I don't recall OpSys details, or know if there is a utility/tool for the job in your choice of OpSys. =What it reminds me of, is what we used to do when archiving files/file sets larger than 1.44MB - zipping them onto more than one diskette. =Try using PHP to read the original file, and copy it out into a set of ~700MB copy/sub-files. Burn each of these onto CDs. Get PHP to output a handy 'key' - report listing what came from where and how to reassemble it all again (in six months' time when all is forgotten). open original file $FileCtr=0; while not eof { create output sub-file nr $FileCtr $MegCtr=1; while $MegCtr700 and not eof { read megabyte write to sub-file $MegCtr++; } //end write loop close sub-file $FileCtr++; } //end read close original file echo Copied original into $FileCtr sub-files; =Regards, =dn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Split files
=Hmm, I'm still come at it from the other way around (all due respect to Jason) - but then I don't recall OpSys details, or know if there is a utility/tool for the job in your choice of OpSys. Well unless it's a *really* obscure OS I'm sure there must be some readily available file splitter utility. No point doing more work than necessary by writing your own file splitting routine :) Think about a multi-volume archiver, like tar. Also pkzip, rar and ace have an option to archive without using compression. bvr. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Split files
=Hmm, I'm still come at it from the other way around (all due respect to Jason) - but then I don't recall OpSys details, or know if there is a utility/tool for the job in your choice of OpSys. Well unless it's a *really* obscure OS I'm sure there must be some readily available file splitter utility. No point doing more work than necessary by writing your own file splitting routine :) Think about a multi-volume archiver, like tar. Also pkzip, rar and ace have an option to archive without using compression. =whilst they are running, will any of these burn a CD (for the original post-er)? =dn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Split files
Hi and thaks for your answer. ... Making any sense? Year, so I have to do it manually (thought someone could preveting me from reinvent the wheel... ;-) What are you really trying to achieve? I'm trying to split a large binary file (2 GB) into peaces of 700 MB to burn it on a cd. It's a part of a backup-mechanism I'm wirting in PHP. Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Split files
On Thursday 24 January 2002 15:34, Martin Thoma wrote: Hi and thaks for your answer. ... Making any sense? Year, so I have to do it manually (thought someone could preveting me from reinvent the wheel... ;-) What are you really trying to achieve? I'm trying to split a large binary file (2 GB) into peaces of 700 MB to burn it on a cd. It's a part of a backup-mechanism I'm wirting in PHP. Maybe you could find a program that will do the split for you then call that from within PHP. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Slurm, n.: The slime that accumulates on the underside of a soap bar when it sits in the dish too long. -- Rich Hall, Sniglets */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split array in 2 halfs
Based on what criteria? if you just want to split the array at element 30, you could use array_splice to get the necessary data... - Original Message - From: Daniel Harik [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, November 01, 2001 2:16 AM Subject: [PHP] split array in 2 halfs Good evening I was wondering how can I split, array that has 60 elements in it, into 2 arrays with 30 elements each? Thank You very much and have a good night :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Split array
See: http://www.php.net/implode - Tim http://www.phptemplates.org On 07 Aug 2001 14:02:04 +0200, Veniamin Goldin wrote: How do I split array so, that I'll get string variable with , delimeter of each array value ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Split array
you could use implode http://www.php.net/manual/en/function.implode.php == Karl Phillipson PHP SQL Programmer Saffron Hill Ventures 67 Clerkenwell Road London EC1R 5BL Saffron Hill: 0207 693 8300 Direct Line: 0207 693 8318 -Original Message- From: Veniamin Goldin [mailto:[EMAIL PROTECTED]] Sent: 07 August 2001 13:02 To: [EMAIL PROTECTED] Subject: [PHP] Split array hello ! Please help me. How do I split array so, that I'll get string variable with , delimeter of each array value ? Thank you! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] split on whitespace, preserving whitespace...
On 20-Jul-2001 Garth Dahlstrom wrote: Hi all, I'm trying to build a spell checker for a web form. What has got me stumped is being able to do a split so that whitespace and words are stored as seperate elements of the same array. ideally, I'd use some form of preg_split to put: This contanswhite space . into an array like: $wordsarr = ('This',' ','contans','','white',' ','space',' ','.') So that I can do a a loop as follows: for ($i = 0; $i count($wordarr); $i++) { if (!trim($wordarr[$i]) == !eregi(trim($wordarr[$i]),'.,/')) { //check spelling //correct errors } echo $wordarr[$i]; } and end up with: This containswhite space . can a split like this be accomplished using preg_split or do I need to go through the string one space at a time in a while loop? -Garth $line='Just a test; (some) text for checking stuff/things.'; $words=preg_split(/[^\w]+/, $line); echo $line, 'P'; while (list ($k, $v) = each($words)) { echo $k - $v, 'BR'; } Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] split on whitespace, preserving whitespace...
On 20-Jul-2001 Garth Dahlstrom wrote: Hi all, I'm trying to build a spell checker for a web form. What has got me stumped is being able to do a split so that whitespace and words are stored as seperate elements of the same array. ideally, I'd use some form of preg_split to put: This contanswhite space . into an array like: $wordsarr = ('This',' ','contans','','white',' ','space',' ','.') So that I can do a a loop as follows: for ($i = 0; $i count($wordarr); $i++) { if (!trim($wordarr[$i]) == !eregi(trim($wordarr[$i]),'.,/')) { //check spelling //correct errors } echo $wordarr[$i]; } and end up with: This containswhite space . can a split like this be accomplished using preg_split or do I need to go through the string one space at a time in a while loop? -Garth start with preg_split(/^\w+/, $foo); (read as: split on one or more non-word charachers) Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split on whitespace, preserving whitespace...
http://www.zend.com/zend/spotlight/spellchecking.php - Original Message - From: Don Read [EMAIL PROTECTED] To: Garth Dahlstrom [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, July 20, 2001 11:41 PM Subject: RE: [PHP] split on whitespace, preserving whitespace... On 20-Jul-2001 Garth Dahlstrom wrote: Hi all, I'm trying to build a spell checker for a web form. What has got me stumped is being able to do a split so that whitespace and words are stored as seperate elements of the same array. ideally, I'd use some form of preg_split to put: This contanswhite space . into an array like: $wordsarr = ('This',' ','contans','','white',' ','space',' ','.') So that I can do a a loop as follows: for ($i = 0; $i count($wordarr); $i++) { if (!trim($wordarr[$i]) == !eregi(trim($wordarr[$i]),'.,/')) { file://check spelling file://correct errors } echo $wordarr[$i]; } and end up with: This containswhite space . can a split like this be accomplished using preg_split or do I need to go through the string one space at a time in a while loop? -Garth start with preg_split(/^\w+/, $foo); (read as: split on one or more non-word charachers) Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split on whitespace, preserving whitespace...
Yup, I hear that... I'm going to use something like the following to do my pspell application... pre ?PHP $text = This contans (brackets) {white} shaz-zam this_under space; .; $matches = preg_split(/([\.\;\:\!\{\}\(\)\s]+)/,$text,-1, PREG_SPLIT_DELIM_CAPTURE); echo pre[$text]br[. implode('|',$matches).]/pre; ? /pre On Fri, 20 Jul 2001 15:11:26 -0500 Brad S. Jackson wrote: I got this to work. I wish I had found this when I wrote our pspell code. I wrote code that loops through each character to get the words and preserve white space. I also wrote a whole bunch of code that strips punctuation from the beginning and end of words and has regex checking for numbers, dates and times. $text = This is a lotta text. How do you like that?; preg_match_all(/(\\S+)|(\\s+)/ms, $text, $array); echo pre; print_r($array[1]); Garth Dahlstrom [EMAIL PROTECTED] wrote: Hi all, I'm trying to build a spell checker for a web form. What has got me stumped is being able to do a split so that whitespace and words are stored as seperate elements of the same array. ideally, I'd use some form of preg_split to put: This contanswhite space . into an array like: $wordsarr = ('This',' ','contans','','white',' ','space',' ','.') So that I can do a a loop as follows: for ($i = 0; $i count($wordarr); $i++) { if (!trim($wordarr[$i]) == !eregi(trim($wordarr[$i]),'.,/')) { //check spelling //correct errors } echo $wordarr[$i]; } and end up with: This containswhite space . can a split like this be accomplished using preg_split or do I need to go through the string one space at a time in a while loop? -Garth Northern.CA ===--- http://www.northern.ca Northern.CA ===-- http://www.northern.ca Canada's Search Engine -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split() function
Thanks for replying ReDucTor but that didn't work either. I tried $line = explode([(|//)], $field); and $line = explode([(|)], $field); and $line = explode([(|\/\/)], $field); with no success. Any other ideas? On Thu, 5 Jul 2001 04:50:29 ReDucTor wrote: $line = explode([(|//)],$field); should work, or you might have to put but thats not \ so you shouldn't need to comment out the slash... - Original Message - From: David A Dickson [EMAIL PROTECTED] To: php-general [EMAIL PROTECTED] Sent: Thursday, July 05, 2001 4:37 AM Subject: [PHP] split() function I have a comma separated spreadsheet with one field that contains two dates. the dates are formatted as dd/mm/yy and separated by either '' or '//' ex:3/12/9228/1/93 or 3/12/92//28/1/93 Problem: I need to split the field at the '' or '//' separator but if I do split('[//]', $field); it splits on the '/' not the '//'. Can I do this in one function call to split() or will I have to do it twice? Get 250 color business cards for FREE! http://businesscards.lycos.com/vp/fastpath/ - End Forwarded Message - Get 250 color business cards for FREE! http://businesscards.lycos.com/vp/fastpath/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split() function
Thanks that helped, this is what I used: if (ereg(, $field)) $line = explode(, $field); else $line = explode(//, $field); On Thu, 5 Jul 2001 05:29:11 ReDucTor wrote: ?php $line2 = explode(, $field); for($i = 0; $i sizeof($line2); $i++){ if($line2[$i] == ) $useand = 1; else if($line[$i + 1] == /){ if($line[$i] == /){ $useslash = 1; } } } if($useand == 1) $line = explode(, $field); if($useslash == 1) $line = explode(//, $field); ? Get 250 color business cards for FREE! http://businesscards.lycos.com/vp/fastpath/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split() function
You don't need a character class here (signified by [] brackets); you can use $line = split('|//', $field); As you can see, this is identical to ReDucTor's solution, except that the brackets are omitted. Character classes only work for single characters, not multiple character strings like '//'. - steve At 3:21 PM -0400 7/4/01, David A Dickson wrote: Thanks for replying ReDucTor but that didn't work either. I tried $line = explode([(|//)], $field); and $line = explode([(|)], $field); and $line = explode([(|\/\/)], $field); with no success. Any other ideas? On Thu, 5 Jul 2001 04:50:29 ReDucTor wrote: $line = explode([(|//)],$field); should work, or you might have to put but thats not \ so you shouldn't need to comment out the slash... - Original Message - From: David A Dickson [EMAIL PROTECTED] To: php-general [EMAIL PROTECTED] Sent: Thursday, July 05, 2001 4:37 AM Subject: [PHP] split() function I have a comma separated spreadsheet with one field that contains two dates. the dates are formatted as dd/mm/yy and separated by either '' or '//' ex:3/12/9228/1/93 or 3/12/92//28/1/93 Problem: I need to split the field at the '' or '//' separator but if I do split('[//]', $field); it splits on the '/' not the '//'. Can I do this in one function call to split() or will I have to do it twice? Get 250 color business cards for FREE! http://businesscards.lycos.com/vp/fastpath/ - End Forwarded Message - -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] split string
$test = 1,2,3; $arrTest = explode(,,$test); foreach($arrTest as $k=$v) { $vname = test.(!$k?:$k); // global for use later global $$vname; $GLOBALS[$vname] = $v; } // now global $test, $test1, $test2 exist etc -Original Message- From: Jacky [mailto:[EMAIL PROTECTED]] Sent: 11 May 2001 16:24 To: [EMAIL PROTECTED] Subject: [PHP] split string I got series of string value like this 1,2,3. And the seires are dynamaic, which means it is not always 1,2,3 but could be more, but always in this format that is separated by , . How do I pick each of value in the series and assign it into new vairiable, like from: $test = 1,2,3; and assign to be $test =1; $test1=2; $test2 =3; Is theer any function that could help me with that? because I need to update table using those value but I cannot use series of value to update, have to break them down to each variable like that. Jack [EMAIL PROTECTED] There is nothing more rewarding than reaching the goal you set for yourself -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split string
On Fri, May 11, 2001 at 10:24:02AM -0500, Jacky wrote: I got series of string value like this 1,2,3. And the seires are dynamic dynamaic, which means it is not always 1,2,3 but could be more, but always in this format that is separated by , . How do I pick each of value in the series and assign it into new vairiable, like from: $test = 1,2,3; and assign to be $test =1; $test1=2; $test2 =3; Is theer any function that could help me with that? because I need to update table using those value but I cannot use series of value to update, have to break them down to each variable like that. Use arrays. $test = 1,2,3; $test = explode(,, $test); // $test[0] == 1; // $test[1] == 2; // $test[2] == 3; -- Jason Stechschulte [EMAIL PROTECTED] -- Well, that's more-or-less what I was saying, though obviously addition is a little more cosmic than the bitwise operators. -- Larry Wall in [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split string
http://www.php.net/manual/en/function.explode.php explode on the comma... you could use while loop and variable variables to take care of the naming... -jack Jacky wrote: I got series of string value like this 1,2,3. And the seires are dynamaic, which means it is not always 1,2,3 but could be more, but always in this format that is separated by , . How do I pick each of value in the series and assign it into new vairiable, like from: $test = 1,2,3; and assign to be $test =1; $test1=2; $test2 =3; Is theer any function that could help me with that? because I need to update table using those value but I cannot use series of value to update, have to break them down to each variable like that. Jack [EMAIL PROTECTED] There is nothing more rewarding than reaching the goal you set for yourself -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split and array logic
I can't quite get the logic to create my own associative arrays: if: $stuff[0]=165.33.114.63 anonymous Mozilla/4.0 $stuff[1]=213.35.354.93 anonymous Mozilla/4.0 how do I end up with: $stuff[0][user]=165.33.114.63 $stuff[0][browser]=Mozilla/4.0 $stuff[1][user]=213.35.354.93 $stuff[1][browser]=Mozilla/4.0 what about : $stuff[0] = array('user' = '156.33.114.63', 'browser' = 'Mozilla/4.0'); and so on -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split string value
Use split('@',$email_address) http://www.php.net/manual/en/function.split.php -- Yasuo Ohgaki ""Jacky"" [EMAIL PROTECTED] wrote in message 005a01c0b8a0$453ede00$[EMAIL PROTECTED]">news:005a01c0b8a0$453ede00$[EMAIL PROTECTED]... Hi people If I have value like [EMAIL PROTECTED] stored in a variable. How do I break it up to be take only the foo.com bit to use that to redirect user back to that URL? Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] split string value again
Try to use explode and keep the second element of the array Just a quick thought .. - Original Message - From: Jacky [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, March 30, 2001 12:52 AM Subject: [PHP] split string value again Hi again have to try again after I have not recieved any advice, I have a vairable that stores email address value. I need to break it so that I will only get the dmain name bit to store in another variable so that I can redirect user to that domain, like if user email is [EMAIL PROTECTED] then I would like to break that and take only foo.com bit to use for navigation. How can I do that? Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split string value again
"try again" after 20 minutes...give people some time to respond!...anyways, you can explode the variable... list($junk,$domain) = explode("@",$email); checkout http://www.php.net/explode you'll use it a lot -jack - Original Message - From: "Jacky" [EMAIL PROTECTED] Date: Thursday, March 29, 2001 5:52 pm Subject: [PHP] split string value again Hi again have to try again after I have not recieved any advice, I have a vairable that stores email address value. I need to break it so that I will only get the dmain name bit to store in another variable so that I can redirect user to that domain, like if user email is [EMAIL PROTECTED] then I would like to break that and take only foo.com bit to use for navigation. How can I do that? Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] split string value again
$addr = "[EMAIL PROTECTED]"; $splitaddr = explode("@",$addr); resulting in $splitaddr[0] = "test"; $splitaddr[1] = "foo.com"; -Stewart -Original Message- From: Jacky [mailto:[EMAIL PROTECTED]] Sent: 29 March 2001 23:52 To: [EMAIL PROTECTED] Subject: [PHP] split string value again Hi again have to try again after I have not recieved any advice, I have a vairable that stores email address value. I need to break it so that I will only get the dmain name bit to store in another variable so that I can redirect user to that domain, like if user email is [EMAIL PROTECTED] then I would like to break that and take only foo.com bit to use for navigation. How can I do that? Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split string value again
try this snippet: ? if (ereg("[^@]+\$", "[EMAIL PROTECTED]", $result)) { $domain = $result[0]; echo $domain; } ? ""Jacky"" [EMAIL PROTECTED] wrote in message 009301c0b8a2$e856f6c0$[EMAIL PROTECTED]">news:009301c0b8a2$e856f6c0$[EMAIL PROTECTED]... Hi again have to try again after I have not recieved any advice, I have a vairable that stores email address value. I need to break it so that I will only get the dmain name bit to store in another variable so that I can redirect user to that domain, like if user email is [EMAIL PROTECTED] then I would like to break that and take only foo.com bit to use for navigation. How can I do that? Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split string value again
thank you everone, sorry about the rush though. I was kind of in urgent need. Anyway, thanks again.:-) Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself" - Original Message - From: Stewart Taylor [EMAIL PROTECTED] To: 'Jacky' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, March 29, 2001 3:51 AM Subject: RE: [PHP] split string value again $addr = "mailto:[EMAIL PROTECTED]; $splitaddr = explode("@",$addr); resulting in $splitaddr[0] = "test"; $splitaddr[1] = "foo.com"; -Stewart -Original Message- From: Jacky [mailto:[EMAIL PROTECTED]] Sent: 29 March 2001 23:52 To: [EMAIL PROTECTED] Subject: [PHP] split string value again Hi again have to try again after I have not recieved any advice, I have a vairable that stores email address value. I need to break it so that I will only get the dmain name bit to store in another variable so that I can redirect user to that domain, like if user email is [EMAIL PROTECTED] then I would like to break that and take only foo.com bit to use for navigation. How can I do that? Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] split string value again
"Jacky" [EMAIL PROTECTED] wrote: I have a vairable that stores email address value. I need to break it so that I will only get the dmain name bit to store in another variable so that I can redirect user to that domain, like if user email is [EMAIL PROTECTED] then I would like to break that and take only foo.com bit to use for navigation. I don't think any of the responses you got took into account email addresses like [EMAIL PROTECTED] If you truely just want domain.tld it's a little more complex. I happened to have written a script a few months ago that does what you want. Even if you don't need something this complex in your case, my code uses 5 or 6 string functions and arrays so it's a pretty good example of how to manipulate strings in PHP. ?php // Expecting a properly formatted email address. $string_in = '[EMAIL PROTECTED]'; // strpos() finds position of '@' character. // substr() returns portion of email address to the // right of '@' (the host). $string_tmp = substr( $string_in, strpos( $string, '@' ) + 1 ); // substr_count() returns the # of occurrences of '.' within the host. $dot_count = substr_count( $string_tmp, '.' ); // If only one dot was found, we're done. if ( $dot_count == 1 ) { $string_out = $string_tmp; } // If more than one dot was found, there's more to do. else { // explode() splits the host into elements of an array. // The elements are the portions of the string between the dots. $parts = explode( '.', $string_tmp ); // count() returns the number of elements. We want the // last 2 elements. Since the array elements begin at 0, not 1, // we need to get elements n-2 and n-1, not n-1 and n, which // might normally be expected. $string_out = $parts[count( $parts ) - 2] . '.' . $parts[count( $parts ) - 1]; } // print the desired output. echo $string_out; ? -- Steve Werby President Befriend Internet Services LLC Tel: 804-355-WEBS http://www.befriend.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]