草庐IT

php - 从推文中查找 URL、@replies 和#hashtags

我正在用PHP构建一个Twitter小东西,我正在尝试解析URL、@replies和#hashtags并将它们变成可点击的链接。@replies将链接到http://twitter.com/repliesHashtags想http://search.twitter.com/search?q=%23hashtags我找到了一个用于解析URL的类,我想知道它是否也可以用于解析@replies和#hashtags://http://josephscott.org/archives/2008/11/makeitlink-detecting-urls-in-text-and-making-the

php - 使用 PHP 的正则表达式,任何包含数字 0-9 的非零数字

我有这个正则表达式:/^[0-9]+$/i在此代码中使用:preg_match('/^[0-9]+$/i',$var);我希望以下内容为真:$变量=1;$var=50;$var=333;以下是错误的:$变量=0;$var=01;$var='abc';我认为除了“0”部分之外,我目前所做的工作......?我仔细阅读了本指南(http://www.phpf1.com/tutorial/php-regular-expression.html),但无法得出完整的答案。任何帮助将不胜感激,谢谢! 最佳答案 /^[1-9][0-9]*$/表示

php - 正则表达式只允许小写字母

这个问题在这里已经有了答案:关闭9年前。PossibleDuplicate:RegularExpressions:low-caps,dots,zerospaces如何将下面的正则表达式更改为只允许使用小写字母?functionvalid_username($username,$minlength=3,$maxlength=30){$username=trim($username);if(empty($username)){returnfalse;//itwasempty}if(strlen($username)>$maxlength){returnfalse;//tolong}if(s

php - 使用正则表达式 preg_match 获取 id video vimeo

我尝试从vimeo的url获取idvideo,但有时查看源代码如下:http://vimeo.com/XXXXXXXXX和其他类似的:http://player.vimeo.com/video/XXXXXXXXX我刚得到idvideo,但它必须使用regExp,因为我必须解析来自博客的内容,并且当我们插入代码html时,我必须像facebook页面那样格式化。这是我制作的正则表达式:/vimeo\.com\/(\w+\s*\/?)*([0-9]+)*$/i你能帮帮我吗?感谢您的帮助。PD:抱歉我的英语不好 最佳答案 为什么不询问Vi

php - CodeIgniter URI 中的百分比符号

我需要将编码字符串传递给CodeIgniterController。示例:DOSOMETHING/Coldplay/Fix+You/273/X+%26+Y/我的问题是百分比符号是不允许的字符。我尝试使用以下内容更改配置文件:$config['permitted_uri_chars']='a-z0-9~%.:_\-\+\%';+可以,但%无效。您能帮我更改此regexp以允许使用%符号吗?提前致谢! 最佳答案 将“-”放在字符串的末尾,否则它会被解释为范围。如您所见,%已在允许的字符列表中。$config['permitted_uri

php - 编译失败 : POSIX collating elements are not supported

我刚刚在我们的服务器上安装了一个网站和旧版CMS,但出现了POSIX编译错误。幸运的是,它只出现在后端,但客户很想摆脱它。Warning:preg_match_all()[function.preg-match-all]:Compilationfailed:POSIXcollatingelementsarenotsupportedatoffset32in/home/kwecars/public_html/webEdition/we/include/we_classes/SEEM/we_SEEM.class.phponline621据我所知,这是导致问题的较新版本的PHP。这是代码:fu

php - 将 2 个正则表达式合并为一个时得到 "two named subpatterns have the same name"

我试图将2个具有相同名称的不同正则表达式合并为一个,但得到的错误消息如下:Warning:preg_match():Compilationfailed:twonamedsubpatternshavethesamenameatoffset276...一个正则表达式如下所示:'%[\s\S]*?(?P[\s\S]*?)%'另一个看起来像这样:'%[\s\S]*?(?P[\s\S]*?)%'我可以毫无问题地按以下方式组合它们:'%([\s\S]*?(?P[\s\S]*?)|[\s\S]*?(?P[\s\S]*?))%'但我不喜欢这种方式,因为我使用了2个名字。我想知道是否有更好的方法来解决这

PHP REGEX - 在换行符处按 preg_split 排列的文本

已编辑:需要拆分数组方面的帮助数组示例:array([0]=>:somenormaltext:somelongtexthere,andsoon...sometimesi'mbreakingdownand...:somenormaltext:somenormaltext)好的,现在通过使用preg_split('#\n(?!s)#',$text);我明白了[0]=>Array([0]=>somenormaltext[1]=>somelongtexthere,andsoon...sometimes[2]=>somenormaltext[3]=>somenormaltext)我想得到这个:[

PHP Preg_match 精确匹配单词

我已存储为|1|7|11|我需要使用preg_match来检查|7|有没有|11|有没有等等,我该怎么做? 最佳答案 在表达式前后使用\b来匹配它作为一个完整的单词:$str1='foobar';//hasmatches(foo,bar)$str2='barmanfoobar';//nomatches$test1=preg_match('/\b(foo|bar)\b/',$str1);$test2=preg_match('/\b(foo|bar)\b/',$str2);var_dump($test1);//1var_dump($te

php - php中的unicode preg_replace问题

我得到了字符串$result="beieinerTemperatur,dieetwa20bis60°CunterhalbdesSchmelzpunktesderkristallinenModifikation"直接来自MySQL表。表格和phpheader都设置为UTF-8我想去除“学位”符号:http://en.wikipedia.org/wiki/Degree_symbol并将其替换为“度”一词以获得:“beieinerTemperatur,dieetwa20bis60degreesCunterhalbdesSchmelzpunktesderkristallinenModifika