執行 ❯
獲取您
自己的 PHP
伺服器
×
更改方向
更改主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>Regex Modifier: cat|dog|fish</h1> <p>How many occurrences of either "cat", "dog", or "fish" are in the text "We have three dogs, one fish, but no cats":</p> <?php $txt = "We have three dogs, one fish, but no cats"; $pattern = "/cat|dog|fish/"; echo preg_match_all($pattern, $txt); ?> <p>The matches were found here:</p> <?php echo preg_replace($pattern, "#", $txt); ?> <p>(Each match was replaced by a # character)</p> </body> </html>
正則表示式修飾符:cat|dog|fish
文字“We have three dogs, one fish, but no cats”中有多少個“cat”、“dog”或“fish”的出現次數?
3
匹配項在此處找到
我們有三隻#,一隻#,沒有#
(每次匹配都替換為“#”字元)