1

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.

1
  • For such a simple case you might as well use str_replace Commented May 13, 2013 at 12:42

1 Answer 1

2

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.

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

1 Comment

ohh so that the reason, damn regex i really can't get that thing :D need to study more about that thing

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.