Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.8k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...