FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » change a string where have number after a word
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: change a string where have number after a word [message #180363 is a reply to message #180357] Tue, 05 February 2013 22:14 Go to previous messageGo to previous message
Jonathan N. Little is currently offline  Jonathan N. Little
Messages: 12
Registered: February 2011
Karma:
Junior Member
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: script php with <img scr...../>
Next Topic: classes in PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 07:37:20 GMT 2024

Total time taken to generate the page: 0.04502 seconds