Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8297

Re: change a string where have number after a word

From "Jonathan N. Little" <lws4art@gmail.com>
Newsgroups comp.lang.php, alt.comp.lang.php, alt.php
Subject Re: change a string where have number after a word
Date 2013-02-05 17:14 -0500
Organization LITTLE WORKS STUDIO
Message-ID <kes07f$f9g$1@dont-email.me> (permalink)
References <a4mqpnjpnuxm.100ko7fi3dxss.dlg@40tude.net> <ker3qg$1jpu$1@yojimbo.hack> <lwbviz8xrn7a$.5zyaw9awc369$.dlg@40tude.net> <kern79$mod$1@dont-email.me> <1gqf3e5pc6vmm.7twr9j9j8d4d.dlg@40tude.net>

Cross-posted to 3 groups.

Show all headers | View raw


nawfer wrote:
>> Couple of questions first.
>>
>> 1) From your example it looks like the comma separated values. it this
>> the case were every value ends with a number?
>
>
> every value ends with one space and a number
> that can also be so I can have this type of words
>
> aaa 4,
> aafagagsg 4,
> afgsgfs 2,
> a affs 4,
> aa adfdf 2,
> afsf ercrrt s 4
>
>
> for the oteher question answer after
>

Then the simplest is what I offered with function always_single_digit() 
where you just chop off the last character and then replace with '4'.

function always_single_digit($v){
// If always each entry always has a single digit number
// you can simply chop off the last as number 4
   return substr($v, 0, -1) . '4';
}

//your sample
$str="aaa 4,aafagagsg 4,afgsgfs 2,a affs 4,aa adfdf 2 afsf ercrrt s 4";
//split into array on ','
$arry=explode(',', $str);
//use array_map to use callback in each element to replace with 4
print implode(',', array_map("always_single_digit", $arry));


-- 
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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