这个'/ /'和'~~'以及PHP正则表达式中的'##'有什么区别? [英] What is the difference between this '/ /' and this '~ ~' and this '# #' in PHP regular expressions?

查看:162
本文介绍了这个'/ /'和'~~'以及PHP正则表达式中的'##'有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我忘记了我在哪里找到了这个但是我遇到了这三个例子,我很尴尬他们产生了相同的输出。这3个例子意味着同样的事情吗?

所有这些之间有什么区别?我熟悉最后一个而不是其他两个。



Hello I forgot where I found this at but I ran into these 3 examples which I'm very
confused about they produce the same output. Do these 3 examples mean the same thing?
What's the difference between all of them? And I am familiar with the last one but not the other two.

<?php
$string = 'I have 2 dogs.';
if(preg_match('~\d~',$string))
{
echo 'The string above contains a numeric character.';
}
else
{
echo 'The string above does not contain a numeric character.';
}
?>







<?php
$string = 'I have 2 dogs.';
if(preg_match('#\d#',$string))
{
echo 'The string above contains a numeric character.';
}
else
{
echo 'The string above does not contain a numeric character.';
}
?>







<?php
$string = 'I have 2 dogs.';
if(preg_match('/\d/',$string))
{
echo 'The string above contains a numeric character.';
}
else
{
echo 'The string above does not contain a numeric character.';
}
?>





我尝试了什么:



谷歌没有我想要的东西所以我想我会在这里得到一个直接答案。



What I have tried:

Google did not have what I was looking for so I thought I'll get a direct answer here.

推荐答案

string ='我有2只狗。';
if(preg_match('〜\d~',
string = 'I have 2 dogs.'; if(preg_match('~\d~',


string))
{
echo'上面的字符串包含一个数字字符。' ;
}
else
{
echo'上面的字符串不包含数字字符。';
}
?>
string)) { echo 'The string above contains a numeric character.'; } else { echo 'The string above does not contain a numeric character.'; } ?>







<?php


string ='我有2只狗。';
if(preg_match('#\d#',
string = 'I have 2 dogs.'; if(preg_match('#\d#',


这篇关于这个'/ /'和'~~'以及PHP正则表达式中的'##'有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆