473,385 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Regular expression: preg_match_all()

1
I've created a form where visitors can input more than one value. They have to use a space as a delimiter. For example: 'mozart beethoven grieg'.
And redundant spaces should be converted to one space.

The only exception is when a value is followed by a comma and a space.
Then the search string should be taken literally.

So if for example you filled in:
mozart amadeus, then this should be split into:
'mozart' and 'amadeus'.
But if you filled in 'mozart, amadeus' it should stay 'mozart, amadeus'.

These values shoud be seperated in put into an array.
So if someone filled in: mozart grieg, beethoven bach.
I would have an array with the values:
array[0] = mozart
array[1] = grieg, beethoven
array[2] = bach

Expand|Select|Wrap|Line Numbers
  1. preg_match_all('/[^\s]+/', $persoon, $m); 
  2.     $array_persoon = $m[0];
  3.  
Is it possible to adjust the preg_match_all() function so that it doensn't use (comma space) as a separator?

Thanks in advance,
Dimpie
Jan 4 '07 #1
0 1044

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Sims | last post by:
Hi, I need some help to split data using regular expression Consider the string '1,2,3', I can split it using, preg_split("/,/", '1,2,3') and i correctly get =1, =2,=3. Now if i have
7
by: YoBro | last post by:
Hi I have used some of this code from the PHP manual, but I am bloody hopeless with regular expressions. Was hoping somebody could offer a hand. The output of this will put the name of a form...
4
by: M Wells | last post by:
Hi All, I couldn't find a regular expressions group to ask this in, so I thought I'd ask here as I'm a little familiar with php's regular expressions syntax. I have a comma delimited text...
2
by: hu8 | last post by:
I must find a regular expression to find every declaration af a variable in a php programm..... I tried: /\$()*(\s|\S)\=(\s|\S)/is But it doesn't reall go :-(
3
by: crescent_au | last post by:
Hi all, I've been trying unsuccessfully to get the text from html page. Html tag that I'm interested in looks like this: <a class=link...
0
by: Mike Zhang | last post by:
I got stuck with regular expression problem. What i want to do is to extract hello world if 'message' is found in the same row. I have gotten until //A. but somehow //B doesn't work. <?php...
0
by: peter stickney | last post by:
Excuse the babbling or lack of sense, it's been a long day. I am making a flat file, static HTML search engine for a site. I downloaded a script from the net and have been working with it for my...
20
by: kosanovic | last post by:
Hello, I'm bad at regular expressions. Would somebody help me: I need to extract all URL to .jpg and .png pictures from a string containing an HTML file (DOM wouldn't work well in what I need). ...
2
by: Shahid | last post by:
Hi, I am parsing an .HTML file that contains following example code: <div> <p class="html_preformatted" awml:style="HTML Preformatted" dir="ltr" style="text-align:left"><span...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.