Straddling Checkerboard Cipher
PHP>=7.1, 226 Bytes

for([,$c,$a,$b,$d,$e,$t]=$argv,$c.=join(preg_grep("#[^$c]#",range(a,z)));$p&lt;30;)$x[in_array($y=["",$a,$b][$p/10].$p++%10,[$a,$b,$b.$d,$b.$e])?"__#."[$m++]:$c[$i++]]=$y;for(;a&amp;$w=$t[$k++];)echo is_numeric($w)?$x["#"].$w:$x[$w];


Online Version

Expanded

for([,$c,$a,$b,$d,$e,$t]=$argv #short variables in input array
,$c.=join(preg_grep("#[^$c]#",range(a,z))) # join the rest of alphabet
;$p&lt;30;) # loop 30 times
  $x[in_array($y=["",$a,$b][$p/10].$p++%10 # is actual position reserved?
  ,[$a,$b,$b.$d,$b.$e]) # reserved positions
    ?"__#."[$m++] # set reserved positions with chars underscore instead spaces to avoid encoding
    :$c[$i++]] # set alpabetic characters
  =$y; # make encoding array
for(;a&amp;$w=$t[$k++];) # loop through string which shall be encoded
  echo is_numeric($w) 
    ?$x["#"].$w # printing for digits
    :$x[$w]; #printing for the other characters