草庐IT

string-matching

全部标签

php - 为什么带有 PCRE_UTF8 的 PHP preg_match_all 在 CLI 上和通过 Apache/mod_php 给出不同的结果?

以下代码在通过CLI和Apache/mod_php运行时产生不同的结果:$pattern."u",//Addu(PCRE_UTF8)modifier"Non-unicode"=>$pattern);echo"Text:\n'$text'\n";foreach($regexpsas$type=>$regexp){$matches=array();$total=preg_match_all($regexp,$text,$matches);echo"\n\n";echo"$typeregex:\n'$regexp'\n\n";echo"Total$typematches:";var_dump

php - 警告 : Illegal string offset 'id'

这个问题在这里已经有了答案:IllegalstringoffsetWarningPHP(17个答案)关闭9年前。我定义了两个变量如下:$pic=get_tax_meta($books->term_id,'books_field_id',true);$imageurl=wp_get_attachment_image_src($pic[id],'list-thumb');print_r($pic)结果如下:Array([id]=>302[src]=>http://localhost/mysite/wp-content/uploads/2013/10/apic.jpg)但是,我从$pic[i

php - 解释这个 PHP 正则表达式的含义 (preg_match_all)

这个问题在这里已经有了答案:Reference-Whatdoesthisregexmean?(1个回答)关闭7年前。模式在PHP中是什么意思:'#^/abc/(?P[^/]++)$#si';//pleaseexpandthispattern'smeaning.什么是字符串可以匹配此模式与preg_match_all?

PHP 类型杂耍, "String"== 0 和 "String"== true

我有一个非常简单的问题。在PHP中,if('abc'==0){//true}if('abc'==1){//false}我知道this页面告诉我们它应该是那样的。但是,我觉得很奇怪。此外,if('abc'==true){//true}if('abc'==false){//false}这两个转换背后的逻辑是什么? 最佳答案 转化1进行字符串和整数比较时,先将字符串转换为整数再进行比较。由于这些字符串中没有前导整数,因此它们会转换为零。转化2任何非空字符串值都是bool值true。来自themanual:Thefollowingthing

php - 错误 : Object of class DateTime could not be converted to string

我在显示值时遇到错误:$thedate=$row2['date'];echo$thedate;在php中,数据库中的值($thedate)是“2015-05-0521:52:31.000”我如何格式化它才能将其作为字符串显示在php页面上?目前它显示错误“DateTime类的对象无法转换为字符串”。 最佳答案 你有一个DateTime对象,所以你必须使用format()格式化你的输出,例如echo$thedate->format("Y-m-d"); 关于php-错误:Objectofcl

php - preg_match 与数字 PHP

当我使用它时:preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/',0.0001);返回值为1,当我使用它时:preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/',0.00001);返回值为0。有人可以告诉我为什么吗?谢谢! 最佳答案 因为小float通常使用指数表示法显示,所以0.00001被转换为1.0E-5,这与正则表达式不匹配。如果你只是这样做,你可以看到这个:echo0.00001;正则表达式应该与字符串一起使用,而不是数字。preg_match('/^[

php - mysqli_real_escape_string() 中默认字符集的安全隐患是什么意思?

在mysqli_real_escape_string()的PHP文档中,写道CautionSecurity:thedefaultcharactersetThecharactersetmustbeseteitherattheserverlevel,orwiththeAPIfunctionmysqli_set_charset()forittoaffectmysqli_real_escape_string().来源mysqli_real_escape_string在关于字符集的进一步链接中,提到Thecharactersetshouldbeunderstoodanddefined,asith

php - preg_match_all 用逗号分隔,值可能包含空格

我目前有一个preg_match_all用于不包含空格的常规字符串,但我现在需要让它适用于每个空格之间的任何内容。我需要abc,hh,heythere,123,hey_there_返回abchh嘿``123hey_there_但是当涉及到空格时,我当前的脚本就会停止。preg_match_all("/([a-zA-Z0-9_-]+)+[,]/",$threadpolloptions,$polloptions);foreach(array_unique($polloptions[1])as$option){$test.=$option.'>';} 最佳答案

php - 如何在 php 中使用 preg_match?

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭7年前。Improvethisquestion我想创建一个表单验证,我想确保用户不会在文本框中输入任何危险代码,所以我想使用preg_match来做到这一点。我不喜欢用户输入的是(不是a-z中的单词,A-Z中的单词和数字)。现在如何在这里使用preg_match?

php - 如何修复 "Recoverable fatal error: Object of class Closure could not be converted to string in..."

当我执行这段代码时出现这个错误。我不知道该怎么办。请帮忙ResultadosparalabúsquedaNúmeroderesultadostotal: 最佳答案 你的问题出在这里$numRows=(function()use($total){if($total你必须在括号之间包装函数,如果你想传递参数,你应该使用use() 关于php-如何修复"Recoverablefatalerror:ObjectofclassClosurecouldnotbeconvertedtostringin