@PiBa:
i realize your asking the enduser to do this, but then the check for 31 characters should perhaps also allow more characters.?
Actually I'd say it works properly as is:
$post['varclientsharedsecret'] = '0123456789\\\\0123456789\\0123456789\\\\\'\'\'';
echo $post['varclientsharedsecret'];
echo "\n";
echo strlen($post['varclientsharedsecret']);
Result:
0123456789\\0123456789\0123456789\\'''
38
Now, consider trying to match/escape things (meant as literal unescaped string) such as \' properly:
preg_match_all("/[\\\\](?!\\'){1}/", $post['varclientsharedsecret'])
just to match a single \ while avoiding hitting the "escaped" ' if it follows. Oooops shit… Well I'd say the escaping it way better left to users.