Skip to main content
Commonmark migration
Source Link

#PHP, 130 109 bytes

PHP, 130 109 bytes

I´d still like it shorter; could save 3 bytes (""<) if B was guaranteed to not contain 0.

for($s=($a=$argv)[1];""<$c=$a[2][$i++];)if($p=strpos(_.$s,$c,$p+1))$s[$p-1]=$a[3][$k++];echo$k<$i-1?$a[1]:$s;

takes arguments from command line. Run with -r.

Replaces the characters when it finds them;
prints copy if all characters have been replaced; original else.

#PHP, 130 109 bytes

I´d still like it shorter; could save 3 bytes (""<) if B was guaranteed to not contain 0.

for($s=($a=$argv)[1];""<$c=$a[2][$i++];)if($p=strpos(_.$s,$c,$p+1))$s[$p-1]=$a[3][$k++];echo$k<$i-1?$a[1]:$s;

takes arguments from command line. Run with -r.

Replaces the characters when it finds them;
prints copy if all characters have been replaced; original else.

PHP, 130 109 bytes

I´d still like it shorter; could save 3 bytes (""<) if B was guaranteed to not contain 0.

for($s=($a=$argv)[1];""<$c=$a[2][$i++];)if($p=strpos(_.$s,$c,$p+1))$s[$p-1]=$a[3][$k++];echo$k<$i-1?$a[1]:$s;

takes arguments from command line. Run with -r.

Replaces the characters when it finds them;
prints copy if all characters have been replaced; original else.

direct replacement with a little golfing saves 21 bytes
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41

#PHP, 130130 109 bytes

I guess I can come up with a shorter solutionI´d still like it shorter; could save 3 bytes (""<) if B was guaranteed to not contain 0.

for(;""<$c=$s=($a=$argv)[2][$i++];[1];""<$c=$a[2][$i++];)if($p=strpos(_.$s=$a[1]$s,$c,$p+1))$r[++$k]=$p$s[$p-1;if($k==$i1]=$a[3][$k++];echo$k<$i-1)while($k)$s[$r[$k]]=$a[3][--$k];echo$s;?$a[1]:$s;

takes arguments from command line. Run with -r.

Replaces the characters when it finds them;
Failsprints copy if B starts with an underscoreall characters have been replaced; original else.

#PHP, 130 bytes

I guess I can come up with a shorter solution.

for(;""<$c=($a=$argv)[2][$i++];)if($p=strpos(_.$s=$a[1],$c,$p+1))$r[++$k]=$p-1;if($k==$i-1)while($k)$s[$r[$k]]=$a[3][--$k];echo$s;

takes arguments from command line. Run with -r.
Fails if B starts with an underscore.

#PHP, 130 109 bytes

I´d still like it shorter; could save 3 bytes (""<) if B was guaranteed to not contain 0.

for($s=($a=$argv)[1];""<$c=$a[2][$i++];)if($p=strpos(_.$s,$c,$p+1))$s[$p-1]=$a[3][$k++];echo$k<$i-1?$a[1]:$s;

takes arguments from command line. Run with -r.

Replaces the characters when it finds them;
prints copy if all characters have been replaced; original else.

Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41

#PHP, 130 bytes

I guess I can come up with a shorter solution.

for(;""<$c=($a=$argv)[2][$i++];)if($p=strpos(_.$s=$a[1],$c,$p+1))$r[++$k]=$p-1;if($k==$i-1)while($k)$s[$r[$k]]=$a[3][--$k];echo$s;

takes arguments from command line. Run with -r.
Fails if B starts with an underscore.