Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

php - Octal to sign in string from array

I want to convert octal sign like 46 to normal sign like &.
The problem is that the input is created with preg_match_all(), put into an array and then retrieved.

If I'd manually input the 46 octal notation into variable with double quotes, like
$input="46";
then PHP would convert it nicely.

But when I have it into an array from preg_match_all(), it returns it unconverted.

I want to convert it because I want to query database (mysql) that have records with "&" sign as ampersand.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

there's an interesting replace trick (or rather hack)

$a = 'a 46 b 75 c';
echo preg_replace('~\\(0dd)~e', '"\\$1"', $a);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...