运行 ❯
获取您自己的
PHP
服务器
×
更改方向
更改主题,暗/亮
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>Regex Modifier: ^W3</h1> <p>Does the text "W3Schools", start with "W3"?:</p> <?php $txt = "W3Schools"; $pattern = "/^W3/"; echo preg_match_all($pattern, $txt); ?> <p>This method returns 1 if there is a match, otherwise 0.</p> <p>The matches were found here:</p> <?php echo preg_replace($pattern, "#", $txt); ?> <p>(The match was replaced by a # character)</p> </body> </html>
正则表达式修饰符: ^W3
文本 "W3Schools" 是否以 "W3" 开头?
1
此方法如果匹配则返回 1,否则返回 0。
匹配项在此处找到
#Schools
(匹配项被替换为 # 字符)