草庐IT

preg_replace_all

全部标签

php - CakePHP 返回 find ('all' ) 使用 'id' 作为数组索引

因此,我尝试使用“产品”的ID作为每个产品的索引键来返回一个查找“全部”数组。通常它返回:array((int)0=>array('Product'=>array('id'=>'1232','category_id'=>'330','name'=>'Product#1',)),(int)1=>array('Product'=>array('id'=>'1245','category_id'=>'310','name'=>'Product#2',)),(int)2=>array('Product'=>array('id'=>'1248','category_id'=>'312','nam

php - 在 preg_replace 中使用 £ 作为定界符可以吗?

我正在将我发现的eregi_replace函数转换为preg_replace,但eregi字符串几乎包含键盘上的每个字符。所以我尝试使用£作为分隔符..它目前正在工作,但我想知道它是否可能会导致问题,因为它是一个非标准字符?这是eregi:functionmakeLinks($text){$text=eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1',$text);$text=eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]

PHP preg_split : Split string by other strings

我想用一系列单词拆分一个大字符串。例如$splitby=array('these','are','the','words','to','split','by');$text='Thisisthestringwhichneedstobesplitbytheabovewords.';那么结果就是:$text[0]='Thisis';$text[1]='stringwhichneeds';$text[2]='be';$text[3]='above';$text[4]='.';我该怎么做?是preg_split最好的方法,还是有更有效的方法?我希望它尽可能快,因为我将拆分数百MB的文件。

php - 用 preg_replace 包裹 <b> 标签中的第一个单词——不能引用全字符串匹配

我用http://gskinner.com/RegExr/生成了以下正则表达式代码它在哪里工作,但是当我用PHP执行它时,它无法在替换字符串中使用匹配项。preg_replace('/(?)\b\w*\b|^\w*\b/','$&','anexample');输出:$&example预期:anexample我知道显然$&没有做正确的事情,但我怎样才能让它工作? 最佳答案 改用这个试试preg_replace('/(?)\b\w*\b|^\w*\b/','$0',$string);$0表示它将成为您的正则表达式中第一个匹配的东西,$1

java - Preg_match PHP 到 java 翻译

我在将php预匹配转换为java时遇到了一些问题。我以为我一切都正确,但它似乎没有用。这是代码:原始PHP:/*Patternfor44CharacterUUID*/$pattern="([0-9A-F\-]{44})";if(preg_match($pattern,$content)){/*DOACTION*/}我的Java代码:finalStringpattern="([0-9A-F\\-]{44})";publicstaticbooleanpregMatch(Stringpattern,Stringcontent){Patternp=Pattern.compile(pattern

php - 如何在 php 中使用 preg match 获得第一个可能的匹配

我有一个这样的字符串varstr='abcd[[testsearchstring]]sometexthere]]';我试过这样*preg_match("/\[\[test.*\]\]/i",$str,$match);如果我执行这个,我会得到如下输出[[testsearchstring]]sometexthere]]我只想要第一场比赛[[testsearchstring]]这可能吗? 最佳答案 简短的回答:是的,你可以。您需要使用惰性量词。所以不是preg_match("/[[test.*]]/i",$str,$match);使用pr

php - Preg_match 从文本中排除单词

我有字符串:FirstWordword2word3wrongWordword4lastWord想要选择以FirstWord开头,以lastWord结尾且不包含wrongWord的字符串。对于第一个也是最后一个,我有:/firstword(.*?)lastword/i但排除wrongword无效。尝试过:/firstword(^wrongWord*?)lastword/i/firstword^((?!wrongWord).)*lastword/i还有更多类似的东西,但没有任何效果。 最佳答案 简单的以下内容有什么问题?/^firstw

php - Symfony 3 中的 Catch-all 路由

我在Symfony2中有一个包罗万象的回退路线,但我无法在Symfony3中工作。我尝试了这个确切的语法(我的Symfony2路由的逐字副本)但没有用。fallback:path:/{req}defaults:{_controller:MyBundle:Default:catchAll}requirements:req:".+"我怎样才能让它在Symfony3中工作?(这实际上是唯一阻止我使用Symfony3并让我保持在v2.8的东西) 最佳答案 这对您有帮助:route1:path:/{req}defaults:{_control

php - 约会的 Preg_match

我正在尝试使用preg_match在PHP中匹配一个日期,拆分它并将它的一部分分配给一个数组,日期看起来像“20100930”,这是我正在使用的代码://Makethetor_fromdatelooknicer$nice_from=$_POST['tor_from'];$matches=array();$ideal_from='';preg_match('/\d{4}\\d{2}\\d{2}\/',$nice_from,$matches,PREG_OFFSET_CAPTURE,0);//if(isset($matches[0]))$nice_from=$matches[0];echo$

php - 用 Str_Replace 替换多个单词

我想用一个特定的词替换多个同义词。结果:本田是一辆汽车。雷克萨斯是一辆汽车。日产是一辆汽车。Scion是一辆汽车。谁能告诉我用“汽车”一词替换“车辆、卡车、轿跑车、轿车”的简洁方法,而不是我单独替换所有4个。谢谢。 最佳答案 $a=array('truck','vehicle','sedan','coupe');$str='Hondaisatruck.Toyotaisavehicle.Nissanisasedan.Scionisacoupe.';echostr_replace($a,'car',str_replace('Toyota