Hello,
I have strings like these:
$line = "Item <name> xxx stock, costs yyy and will sell for amount zzz";
Problem is <name> can consist of 1..n words. Most items are single words,
but some are up to 8 in my example, and there are is no set maximum (well,
max is 80 chars I believe, have to look in the stock db, not too relevant I
think)
I found this out the hard way. I thought I was clever (never do that again)
by doing this:
$words = explode (" ", $line);
$itemname = $words [1];
This only works for single-word names.
Now I want to create or use an existing function that simply copies
everything between Item and the first numerical substr.
The function then should look like:
$itemname = GetSubStr ("Item" , <numerical> , $line);
<numerical> should be a template of some sort I think.
Hope I make myself clear, can you help me ?
TIA
Pjotr 4 1799
Pjotr Wedersteers <x3****@westerterp.com> wrote: $line = "Item <name> xxx stock, costs yyy and will sell for amount zzz";
.... Now I want to create or use an existing function that simply copies everything between Item and the first numerical substr. The function then should look like:
$itemname = GetSubStr ("Item" , <numerical> , $line); <numerical> should be a template of some sort I think.
See the manual for regular expressions (eg http://php.net/preg_match):
/Item(.*?)\d+/
--
Daniel Tryba
"Daniel Tryba" wrote: Pjotr Wedersteers <x3****@westerterp.com> wrote: $line = "Item <name> xxx stock, costs yyy and will sell for amount zzz"; .... Now I want to create or use an existing function that simply copies everything between Item and the first numerical substr. The function then should look like:
$itemname = GetSubStr ("Item" , <numerical> , $line); <numerical> should be a template of some sort I think.
See the manual for regular expressions (eg http://php.net/preg_match):
/Item(.*?)\d+/
preg_match("/Item\s(.*)\s\d+/", $line, $Arr);
$Item = $Arr[1];
-- http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Copying-...ict132890.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=443944
steve wrote: "Daniel Tryba" wrote: > Pjotr Wedersteers <x3****@westerterp.com> wrote: > > $line = "Item <name> xxx stock, costs yyy and will sell > for amount zzz"; > .... > > Now I want to create or use an existing function that simply > copies > > everything between Item and the first numerical substr. > > The function then should look like: > > > > $itemname = GetSubStr ("Item" , <numerical> , $line); > > <numerical> should be a template of some sort I think. > > See the manual for regular expressions (eg http://php.net/preg_match): > > /Item(.*?)\d+/ > >
preg_match("/Item\s(.*)\s\d+/", $line, $Arr); $Item = $Arr[1];
Thanks for the tips! I'm studying regexp now... Geez, I've seen less complex
ones in my life, lol. gettin' old!
KR
Pjotr
"Pjotr Wedersteers" wrote: steve wrote: "Daniel Tryba" wrote: > Pjotr Wedersteers <x3****@westerterp.com> wrote: > > $line = "Item <name> xxx stock, costs yyy and will sell > for amount zzz"; > .... > > Now I want to create or use an existing function that simply > copies > > everything between Item and the first numerical substr. > > The function then should look like: > > > > $itemname = GetSubStr ("Item" , <numerical> , $line); > > <numerical> should be a template of some sort I think. > > See the manual for regular expressions (eg http://php.net/preg_match): > > /Item(.*?)\d+/ > >
preg_match("/Item\s(.*)\s\d+/", $line, $Arr); $Item = $Arr[1];
Thanks for the tips! I’m studying regexp now... Geez, I’ve seen less complex ones in my life, lol. gettin’ old! KR Pjotr
Pjotr, regex is hard to learn, but once learned, you cannot do without
it.
-- http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Copying-...ict132890.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=444336 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: franky.backeljauw |
last post by:
Hello,
following my question on "std::copy versus pointer copy versus member
copy", I had some doubts on the function memcpy, as was used by tom_usenet
in his reply.
- Is this a c++ standard...
|
by: Friday |
last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of
dot.net (and all things Windows, for that matter).
As part of an experiment (to learn enough ASP/VB.net to port a series
of ...
|
by: simon |
last post by:
hello,
what i'm looking to do is store the path of the app on a the server
for reuse in the site.
my thoughts so far are...
-make a key in the web.config file
-retrieve the value in globals.asax...
|
by: Nathan Sokalski |
last post by:
I have a Control that I want to copy as a copy of the Control, not a copy of
the reference to the original. My reason for doing this is because some of
the methods I would calling would prevent...
|
by: Kelii |
last post by:
I've been trying to get this piece to work for a few hours, but have
given up. I hope someone out there can help, I think the issue is
relatively straightforward, but being a novice, I'm stumped....
|
by: Control Freq |
last post by:
Hi,
Not sure if this is the right NG for this, but, is there a convention
for the variable names of a Session variable?
I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any...
|
by: shalini jain |
last post by:
Hi all,
I dont know much of PERL so i m facing a problem in trying to remove the variable length of word from the string. I have written a code for it. Please guide me whether i will get the...
|
by: Bob Jones |
last post by:
Ok, I am curious if this can be done in C# 2.0 via some internal .net
functionality or if I have to do a coversion myself such as a copy
construtor or override the explicit operator.
I have 3...
|
by: raylopez99 |
last post by:
Beware newbies: I spent a day before I figured this out: copying a
bitmap (image) file to file is not quite like copying a text file--you
have to do some tricks (see below), like using a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |