• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

hi again

see this again :

person1only--
person1only,person2only--
person1only,person2only,person3only--
person1only,person2only,person3only,person4only--
person1only,person2only,person3only,person4only,person5only--
person1only,person2only,person3only,person4only,person5only,person6only--
person1only,person2only,person3only,person4only,person5only,person6only,person7only--

now what i want is

some how in my script i get number 2 and 4

how to replace person2only and person4only with "nothere" by the return number that i get from my script?

0
abangbatax
Asked:
abangbatax
  • 2
  • 2
1 Solution
 
Roger BaklundCommented:
I'm not sure if I understand this question.

You can use str_replace() to replace substrings. Your big string is stored in $result:

$new_result = str_replace(array('person2only','person4only'),'nothere',$result);

http://php.net/str_replace
0
 
abangbataxAuthor Commented:
$new_result = str_replace(array('person2only','person4only'),'nothere',$result);

i think you almost get what i mean

ok, like this

$return = "2,4";

$string = person1only,person2only,person3only,person4only,person5only,person6only,person7only--

i want the output to be :

$output = "person1only,nothere,person3only,nothere,person5only,person6only,person7only--";

how? :D
0
 
Roger BaklundCommented:
Like this:
$return = "2,4";
$arr = array();
foreach(explode(',',$return) as $number)
  $arr[] = 'person'.$number.'only'; 
$new_result = str_replace($arr,'nothere',$result);

Open in new window

0
 
agamalCommented:
tested or not ...... i hope it worked
0
 
abangbataxAuthor Commented:
thank you! that exactly i want...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now