![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| L.S. I am trying to cut a string into substrings. The string at hand looks something like this: $data='one|two|three|four\nfive|six|seven|eight'; //observe the chr(10) in the middle I would like to have this split two times. Once to give me the two 'sentences' 'one|two|three|four' and 'five|six|seven|eight'. Then, each of these sentences would be split into their repective words. Initially I thought it would be simple: $sentence=preg_split("\n",$data); //should give me an array $sentence $word=preg_split("|",$sentence[0]); //should give me an array $word Unfortunately this doesn't work and now I am caught up in a new world of 'regular expression functions' that doesn't seem to make any sense. Can you please help me to get this split function to do what I need? Thanks for your reply, Peter. | |||
| Advertisements |
| | #3 | ||
| Peter wrote: > L.S. > > I am trying to cut a string into substrings. The string at hand looks > something like this: > > $data='one|two|three|four\nfive|six|seven|eight'; //observe the chr(10) in > the middle > > I would like to have this split two times. Once to give me the two > 'sentences' 'one|two|three|four' and 'five|six|seven|eight'. Then, each of > these sentences would be split into their repective words. Initially I > thought it would be simple: > > $sentence=preg_split("\n",$data); //should give me an array $sentence > $word=preg_split("|",$sentence[0]); //should give me an array $word > As pointed out elsewhere, it is better to use explode. However, if you are doing things like this with pcre, you have to bear in mind that if your expressions contain newlines, you have to use a multiline modifier. Have a read and a play with it (read the manual stuff on modifiers) Matt | |||
| Featured Websites | ||||
|
![]() |
| Tags: preg_split, problem |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Was there a UK GPS sat problem? | Darren Griffin | GPS | 0 | 06-25-2007 11:51 PM |
| GPS problem | Projeto Traipse | GPS | 0 | 06-12-2007 3:03 PM |
| Same Problem | Reggie Culwell | Windows | 0 | 05-28-2007 11:28 PM |
| VPN Problem | Trevor Best | Windows | 0 | 05-28-2007 11:28 PM |
| replicatable Folder Search problem : is source of problem Windows Desktop Search ? | Bill Woodruff | MSN questions | 0 | 05-28-2007 1:45 AM |
| Featured Websites | ||||
|