草庐IT

php - Laravel 中地址字段的正则表达式

您好,我需要验证如下地址C/s-2,abc,pqrC/s/2,abc,pqr221BBakerStreet101,BakerStreet,London,UK221-B,BakerStreetetc基本上是在寻找我可以使用laravel的验证来验证的标准地址类型我试过下面的表达式'address'=>'required|regex:/^(?=.*[0-9])[-,\/0-9]+$/','address'=>'required|regex:/[^a-zA-Z0-9\/-]|[,\/]$/s','address'=>'required|regex:/(^([0-9]+)?[a-zA-Z]+$

php - preg_match 模式在 php v 5 中不起作用

我使用的是PHP5.4.45版。我在php版本7中测试了这段代码并且工作正常但在版本5.4.45中不起作用$string='9301234567';if(preg_match('/^\9\d{9}/',$string)){$string='0+1'.$string;return$string;}在v7中返回:0+19301234567但在v5.4.45中返回(preg_match返回false)9301234567我如何在phpv5.4.45中使用preg_match('/^\9\d{9}/',$string)?谢谢 最佳答案 简介

php - 字符串的特殊 preg_match

这是我的字符串:================================================================================INPUTFILE================================================================================NAME=CO-c0m1.txt|1>!HFdef2-TZVPoptnumfreq|2>|3>%scf|4>convergencetight|5>end|6>|7>*xyz01|8>C000|9>O001|10>*|11>|12>****

php - 替换所有字符直到反斜杠n次

我有一个字符串,一个文件路径,类似$string="customer-service/tweep/cs/gsergsergrs/2017-20190Course-Schedule.pdf"我想用3个破折号替换反斜杠之前的所有字符,以便返回:$string=---/---/---/---/2017-20190Course-Schedule.pdf我试过使用这个preg_replace模式,但它返回---/2017-20190Course-Schedule.pdfpreg_replace("/(.+\/)+/","---/",$string);有什么方法可以在模式匹配的每个实例上运行替换?

php - 替换为 preg_replace 中的动态变量

我遇到了这个问题,就是我有一个这样的数组:$array=['name'=>'John','email'=>john@gmail.com];和这样的字符串示例:$string='Hi[[name]],youremailis[[email]]';问题很明显,将姓名替换为John,并将电子邮件替换为john@gmail.com。我的尝试://checkif$stringhas[[]]pattern$stringHasBrackets=preg_match_all('/\[\[(.*?)\]\]/i',$string,$matchOutput);if($stringHasBrackets){f

php - 如何使用正则表达式拆分文件扩展名

如何使用正则表达式从asddhj123.png.png拆分为123.png我试过下面的正则表达式,但第一个扩展仍然涉及:(/[a-zA-z.]|\.(jpg|png)$/我希望它会回来:asdasd123.jpg.jpg=>123.jpgdsds345.png.png=>345.png 最佳答案 此表达式可能会返回所需的输出:(?i)\d+\.(?:jpe?g|png)Ifyouwishtoexplore/simplify/modifytheexpression,it'sbeenexplainedonthetoprightpanel

PHP:将 preg_replace 与 htmlentities 结合使用

我正在将RSS写入JSON解析器,作为其中的一部分,我需要在任何标签上使用htmlentities()在描述标签内找到。目前,我正在尝试使用preg_replace(),但我有点吃力。我当前的(非工作)代码如下所示:$pattern[0]="/\(.*?)\/is";$replace[0]=''.htmlentities("$1").'';$rawFeed=preg_replace($pattern,$replace,$rawFeed);如果您对此也有更优雅的解决方案,请分享。谢谢。 最佳答案 简单。使用preg_replace_c

php - 通过 PHP 为搜索创建索引

如何使用PHP只搜索独特的词,以便我可以学习进行搜索的基础知识?我在为问题制作多维数组时遇到了一些问题。我的第一个unsuccessfulattempt如下。#1$result=pg_query_params($dbconn,"SELECTquestion_id,bodyFROMquestions",array());while($row=pg_fetch_array($result)){$question_body[$row['question_id']]['body']=$row['body'];$question_index=explode("",$question_body[$

php - 正则表达式用逗号和空格分割字符串,但忽略内部引号和括号

我需要用逗号和空格分割字符串,但忽略里面的引号、单引号和括号$str="Questions,\"Quote\",'singlequote','comma,inside'(insideparentheses)space#specialchar";这样得到的数组就会有[0]Questions[1]Quote[2]singlequote[3]comma,inside[4]insideparentheses[5]space[6]#specialcharmyatualregexpis$tags=preg_split("/[,\s]*[^\w\s]+[\s]*/",$str,0,PREG_SPLI

php - 从 Wordpress 标题返回文本的简单正则表达式 - qtranslate 插件

我正在使用qtranslatewordpress插件以多种语言存储博客内容。现在我需要从qtranslate标签中提取内容。$post_title="EnglishtextItaliantext";从该字符串返回文本和语言的php代码和正则表达式是什么?非常感谢! 最佳答案 尝试这样的事情:EnglishtextItaliantext";$regexp='/([^/i';if(preg_match_all($regexp,$post_title,$matches)){$titles=array();$count=count($mat