lemoncodes
lemoncodes

Reputation: 2421

preg_replace() on encoded string in CI

I have this encoded string

hhNa0fUcOc3k0jUhPcRBJshpiXLpUSug+NhgPk89O7eSjerHk6go360U9rl8LazZo6DR6M1N4IqG0PYIwPyKhQ==

and I used the preg_replace() to replace all the +,/,= on that string with $, but the result is just the same as above, the encoded string wasn't parsed well. Basically I wanted to just change all the +=/ characters within that string for some security purposes. Here is what I did, following is my code snippet:

echo $code.'<br/>';
echo preg_replace('/\+\=\//', '$', $code);

where $code the one given earlier. I can't seem to find the problem why it doesn't replace the specified characters with the one i want.

Upvotes: 1

Views: 191

Answers (1)

Dogbert
Dogbert

Reputation: 222368

You need to put the 3 characters in alternation (|) groups.

preg_replace('/\+|\=|\\//', '$', $code);
→ string(88) "hhNa0fUcOc3k0jUhPcRBJshpiXLpUSug$NhgPk89O7eSjerHk6go360U9rl8LazZo6DR6M1N4IqG0PYIwPyKhQ$$"

Your current code will match the sequence +=/ instead of matching the characters individually.

Upvotes: 2

Related Questions