1

I have the following code:

        $qSeq        = "ATTA";
        $suchmuster  = array("/A/","/T/","/G/","/C/","/U/");
        $ersetzungen = array("T","A","C","G","A");
        $qSeq        = preg_replace($suchmuster, $ersetzungen, $qSeq);
        echo $qSeq;

My aim is that i.e. ATTA becomes TAAT, this logic works fine in Ruby, but PHP will kinda produce AAAA. Any idea how this might work with PHP ?

Tnx!

1
  • 3
    If your replace may entail changing letters that you've already changed, then use strtr() Commented Feb 24, 2015 at 14:02

1 Answer 1

1

If your replace may entail changing letters that you've already changed, then use strtr()

$qSeq = 'CATGUT';
$suchmuster  = array("A","T","G","C","U");
$ersetzungen = array("T","A","C","G","A");
$qSeq        = strtr($qSeq, array_combine($suchmuster, $ersetzungen));
echo $qSeq;

gives

GTACAA
Sign up to request clarification or add additional context in comments.

1 Comment

The "first" syntax of strtr seems more appropriate in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.