Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

adding a 3 digit string to another string

the4string
want
th2e4sxtrin2g

adding 2x2

longstring
want
lo2ngsxtrin2g
0
rgb192
Asked:
rgb192
1 Solution
 
nanharbisonCommented:
Are you always going to want to insert characters in the second, sixth and second to last place?
0
 
grahamnonweilerCommented:
$a="longstring";
$b="2x2";
$x=strlen($a);
if($x>5) {
$m=intval($x/2);
$c=substr($a,0,2).substr($b,0,1).substr($a,2,$m-2).substr($b,1,1).substr($a,(2+($m-2)),$m-2).substr($b,2,1).substr($a,(2+(($m-2)*2)));
}  else  {
$c=substr($a,0,1).substr($b,0,1).substr($a,1,1).substr($b,1,1).substr($a,2,1).substr($b,2,1).substr($a,3);
}
echo($c);

Open in new window

0
 
rgb192Author Commented:
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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