Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #8279
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!yojimbo.hack!news.tokachu.com!.POSTED!not-for-mail |
|---|---|
| From | Salvatore <sal@yojimbo.hack.invalid> |
| Newsgroups | comp.lang.php, alt.comp.lang.php, alt.php |
| Subject | Re: change a string where have number after a word |
| Date | Tue, 5 Feb 2013 14:09:20 +0000 (UTC) |
| Organization | Yojimbo NNTP server |
| Lines | 45 |
| Message-ID | <ker3qg$1jpu$1@yojimbo.hack> (permalink) |
| References | <a4mqpnjpnuxm.100ko7fi3dxss.dlg@40tude.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Trace | yojimbo.hack "kq(Iga%czn" |
| X-Complaints-To | usenet(at)tokachu(dot)com |
| User-Agent | slrn/0.9.9p1 (FreeBSD) |
| X-Watermark | "Q(<g$Wn^Dp`xGx67m5+Q2l|l|%b{RKt!&volz`j>?4QqD<pR}ObPPEAiOs_X" |
| X-Reader-User | hidden; display="24EEr1QzLVIfRpxx65/wVSkg68k" |
| Xref | csiph.com comp.lang.php:8279 |
Cross-posted to 3 groups.
Show key headers only | View raw
On 2013-02-05, nawfer <novalidsforspam@alt.al> wrote:
> "arts 4, tested 4, passenger 2"
>
> "arts 4, tested 4, passenger 2, arrived 2"
>
> "arrived 2, tested 4, passenger 2, arts 4"
>
> how can change this type of string for to have only the word with 4 at the
> end?
>
>
> so
> "arts 4, tested 4"
> first steps taht remove the words with 2 at the end;
> and 2nd steps for to have
> "arts, tested"
>
> and if with regex the solution is also more fast
To begin, it's far easier to use a regular expression. The regex I will
use is the following:
/(\w+)\s(4,|4$)/
And here's the PHP code I wrote up:
<?php
$string = 'arrived 2, tested 4, passenger 2, arts 4';
$regex = '/(\w+)\s(4,|4$)/';
$matches = array();
if (preg_match_all($regex, $string, $matches)) {
$actualMatches = array_shift($matches);
$string = implode(' ', $actualMatches);
}
echo "$string\n";
?>
I'm sure that there's a better way to do this, but my method appears to
work well.
--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
change a string where have number after a word nawfer <novalidsforspam@alt.al> - 2013-02-05 14:21 +0100
Re: change a string where have number after a word Salvatore <sal@yojimbo.hack.invalid> - 2013-02-05 14:09 +0000
Re: change a string where have number after a word nawfer <novalidsforspam@alt.al> - 2013-02-05 18:36 +0100
Re: change a string where have number after a word Salvatore <sal@yojimbo.hack.invalid> - 2013-02-05 19:30 +0000
Re: change a string where have number after a word "Jonathan N. Little" <lws4art@gmail.com> - 2013-02-05 14:40 -0500
Re: change a string where have number after a word nawfer <novalidsforspam@alt.al> - 2013-02-05 20:50 +0100
Re: change a string where have number after a word "Jonathan N. Little" <lws4art@gmail.com> - 2013-02-05 17:14 -0500
Re: change a string where have number after a word nawfer <novalidsforspam@alt.al> - 2013-02-06 11:47 +0100
Re: change a string where have number after a word "Jonathan N. Little" <lws4art@gmail.com> - 2013-02-06 09:58 -0500
csiph-web