PHP:如何修复我的preg_replace代码

If I have a string like

$str = "Hello [Page 1] World [Page 23] Hello [Page 35] World [Page 624]";

And I want to remove all instances of "[Page #]"

How would I go about doing that?

Here's what I've got so far...

preg_replace('[Page [0-9]]', '', $str);
preg_replace('/\\[Page [0-9]+\\]/', '', $str)

Remember that [ and ] are class delimiters. When you want to use them as literals you need to escape them (prefix with \) first. So:

/\[Page [0-9]+\]/i

is probably your best bet. Surround the pattern with /, add a + to your number range to match "1+ numbers", and the final i means case-insensitive match (P or p in "Page") (remove if that's not your intent).

/\[Page \d+\]/

works, too. \d is shorthand for number-chars.