草庐IT

Preg_match

全部标签

php - Symfony2 "Parameter ""for route ""must match "[^/]++"(""given) to generate a corresponding URL."

我有这个路线文件:indexRechercheZones:path:/gestionzonestechniquesdefaults:{_controller:MySpaceGestionEquipementsTechniquesBundle:GestionZonesTechniques:indexZonesTechnique}requirements:methods: GETmodifierZones:path:/gestionzonestechniques/modifier/{nom}defaults:{_controller:MySpaceGestionEquipementsTec

php - preg_replace() 替换太多

我正在开发一个简单的SQL调试器,它将接受参数化变量并尝试相应地替换它们,这样如果一条SQL有问题,那么我可以将它直接复制并粘贴到我的RDBMS中以处理查询,并希望如此更快地调试问题。到目前为止,我基本上已经有了这个,但是它替换了太多:导致select*fromtable_namewherecommentlike'%thatisanice'monkeyzeus@example.com'butthisone%'andemail='monkeyzeus@example.com'andstatus='active'请注意,位置1的'monkeyzeus@example.com'正在从位置0进

php - PHP 中的正则表达式 : find the first matching string

我想在非常非常长的文本中找到第一个匹配的字符串。我知道我可以使用preg_grep()并获取返回数组的第一个元素。但是如果我只需要第一场比赛(或者我知道提前只有一场比赛),这样做效率不高。有什么建议吗? 最佳答案 preg_match()?preg_match()returnsthenumberoftimespatternmatches.Thatwillbeeither0times(nomatch)or1timebecausepreg_match()willstopsearchingafterthefirstmatch.preg_m

PHP preg_replace oddity with £ pound sign and ã

我正在应用以下功能效果很好,但如果我将ã添加到preg_replace中,比如$new_string=preg_replace("/[^a-zA-Z0-9\sçéèêëñòóôõöàáâãäåìíîïùúûüýÿ]/","",$string);$string="Thisissometextandnumbers12345andsymbols!£%^#&$andforeignletterséèêëñòóôõöàáâäåìíîïùúûüýÿã";它与英镑符号£冲突,将英镑符号替换为黑色方block中未识别的问号。这并不重要,但有人知道这是为什么吗?谢谢,巴里更新:谢谢大家。更改函数添加u修饰

php - 使用 preg_replace 返回引用数组键并替换为值

我有这样一个字符串:http://mysite.com/script.php?fruit=apple我有一个这样的关联数组:$fruitArray["apple"]="green";$fruitArray["banana"]="yellow";我正在尝试在字符串上使用preg_replace,使用数组中的键来反向引用apple并将其替换为绿色,如下所示:$string=preg_replace('|http://mysite.com/script.php\?fruit=([a-zA-Z0-9_-]*)|','http://mysite.com/'.$fruitArray[$1].'/'

php - 这是 php 中的快速进程 strpos()/stripos() 或 preg_match()

我只想知道在php中,strpos()/stripos()或preg_match()函数中哪一个会更快。 最佳答案 我找到了thisblog已经对你的问题做了一些测试,结果是:strpos()比preg_match()快3-16倍stripos()比strpos()慢2-30倍stripos()比preg_match()快20-100%无大小写修饰符“//i”在preg_match()中使用正则表达式并不比使用正则表达式快长字符串在preg_match()中使用utf8修饰符“//u”使其慢2倍使用的代码是:

PHP 数组 : summing values with matching dates

我正在尝试弄清楚如何对具有相似日期的多维数组的某些值求和。这是我的数组:2011,'month'=>5,'day'=>13,'value'=>2),array('year'=>2011,'month'=>5,'day'=>14,'value'=>5),array('year'=>2011,'month'=>5,'day'=>13,'value'=>1),array('year'=>2011,'month'=>5,'day'=>14,'value'=>9));?>这是我希望输出的样子:2011,'month'=>5,'day'=>13,'value'=>3//thesumof1+2),a

php - 尝试在 Preg_Match 中查找正斜杠

我已经搜索了几个小时,试图找到解决这个问题的方法。我正在尝试确定REQUESTURI是否合法并从那里分解它。$samplerequesturi="/variable/12345678910";判断是否合法,第一段variable只有字母,长度可变。第二部分是数字,总共应该有11个。我的问题是转义正斜杠,以便它在uri中匹配。我试过:preg_match("/^[\/]{1}[a-z][\/]{1}[0-9]{11}+$/",$samplerequesturi)preg_match("/^[\\/]{1}[a-z][\\/]{1}[0-9]{11}+$/",$samplerequestu

PHP:Preg_match_all 将 html 提取到字符串中

我有这样的html:Tagged:sports,entertain,funny,comedy,automobile,moretags.如何将运动、娱乐、搞笑、喜剧、汽车提取到字符串中我的phppreg_match_all看起来像这样:preg_match_all('/(.*?),/',$this->page,$matches);echovar_dump($matches);echoimplode('',$tags);它不起作用。 最佳答案 我不确定您是如何从中获取$this->page的,但是以下内容应该会如您所料:http://i

PHP preg_split 忽略转义序列

我怎样才能一个一个地拆分字符串但忽略转义字符?在我的例子中,我有字符串:-\ntest\rtest\n我希望它是这样的:-Array([0]=>\n[1]=>t[2]=>e[3]=>s[4]=>t[5]=>\r[6]=>t[7]=>e[8]=>s[9]=>t[10]=>\n)有人说用preg_split,但我对正则表达式了解不多。 最佳答案 反斜杠需要在RegEx中转义。当引用一个实际的反斜杠时,你需要一系列的三个\\\正则表达式匹配preg_match_all("/\\\?[^\\\]/",$str,$matches);现场演示代