草庐IT

Search-and-replace

全部标签

PHP : Search all record from array with specific value

我有2个数组。$a=(array('number'=>$value,'name'=>$name),array('number'=>$value,'name'=>$name),array('number'=>$value,'name'=>$name),);$b=(array('number'=>$value,'address'=>$address),array('number'=>$value,'address'=>$address),array('number'=>$value,'address'=>$address),...);现在,假设$a中的“number”=10的特定记录。在P

Php str_replace 不适用于特殊字符

为什么这没有按预期工作:echostr_replace("é","é","FédérationCamerounaisedeFootball");结果:"FédérationCamerounaisedeFootball"我希望有:"FédérationCamerounaisedeFootball" 最佳答案 你做错了。这个字符串没有错误,需要替换,它只是用UTF-8编码。您所要做的就是utf8_decode('FédérationCamerounaisedeFootball')。更新:您看到FédérationCamerou

php - PHP 中 "filter_var"和 "preg_replace"之间的后端区别是什么?

我有来自数据库(非常受控的输入)的数字,它们前后都有下划线。它们是这样存储的:_51__356_它们不会以任何其他格式存储,但有时我只需要从中获取数字。我选择使用其中之一$x=filter_var($myNumber,FILTER_SANITIZE_NUMBER_INT);或$y=preg_replace("/[^0-9]/","",$myNumber);我不确定后端两者之间的细微差别,但它们都能产生我所需要的(无论如何,我是这么认为的),所以我使用哪个并不重要。使用这些选项的优缺点是什么?(例如,是否有人使用数组或其他我可能需要了解的奇怪事物?有人使用了太多资源吗?)

PHP 强制 str_replace 只替换一个结果

这个问题在这里已经有了答案:Usingstr_replacesothatitonlyactsonthefirstmatch?(23个回答)关闭7年前。这是完美的工作:$replaceLyrics=str_replace('story','_____','ThestoryofmylifeItakeherhomeIdriveallnighttokeepherwarmandtimeIsfrozen(thestoryof,thestoryof)');echo$replaceLyrics;输出:The_____ofmylifeItakeherhomeIdriveallnighttokeepher

php preg_split 没有松散的文本,。 : and so forth

我尝试使用preg_split拆分文本,但我没有得到它的正则表达式。例子:Isearch1,regexto:no.Or...yes!应该得到:Array([0]=>I[1]=>search[2]=>1[3]=>,[4]=>regex[5]=>to[6]=>:[7]=>no[8]=>.[9]=>Or[10]=>...[11]=>yes[12]=>!)我尝试了以下代码:preg_split("/([\s]+)/","Isearch1,regexto:no.Or...yes!")结束于:Array([0]=>I[1]=>search[2]=>1,[3]=>regex[4]=>to:[5]=>

php - 如何在 CI 中使用 OR 和 AND 运算符进行查询?

我尝试通过ActiveRecords在Codeigniter中进行查询:if(isset($data['where']['and'])){$this->db->where($data['where']['and']);}if(isset($data['where']['or'])){$this->db->or_where_in('idSpec',$data['where']['or']);}我想得到:WHEREname=1AND(idSpec=2ORidSpec=3ORidSpec=4);但现在我得到:WHEREname=1ORidSpec=2ORidSpec=3ORidSpec=4;

php - 如何在 YII2 ActiveRecord 查询中说 (a AND b) OR (c AND d)?

我在使用YII2的ORM时遇到了困难,它没有记录一些非常简单的典型SQL案例,比如伪代码SELECT*FROMtableWHERE(a=1ANDb=2)OR(a=3ANDb=4)我尝试过的://shouldrepresentthecommentedlogic,butdoesnotDemo::find()->where(...)//(conditionone->andWhere(...)//ANDconditiontwo)->orWhere(...)//OR(!)(conditionthree->andWhere(...)//ANDconditionfour)问题:在YII2中,wher

php - Laravel 5.1 auth attempt with extra parameters using default auth controller and middleware

如何使用默认身份验证Controller和中间件使用额外参数覆盖Laravel5.1身份验证尝试?假设我有一个状态为=active或inactive的额外字段。我该如何编写该尝试方法? 最佳答案 如documentation中所述您可以传递一个变量数组,它们的键是您要在数据库中验证值的列。$request->get('email'),'password'=>$request->get('password'),'active'=>$request->get('active')]);if($attempt){returnredirect

PHP str_replace 空格的任意组合

我想确保字符串中的/字符始终在两边填充一个空格。对于PHP,我目前使用的是str_replace,但我不能保证所有情况都适用于任意数量的空格。$original="Yes/No";echostr_replace("/","/",$original)."\n";echostr_replace("/","/",$original)."\n";echostr_replace("/","/",$original)."\n";我知道我传递给str_replace函数的第一个参数/参数是错误的,因为它没有考虑周围的字符。下面是我想要实现的一些例子:OriginalDesired==========

php - 如何使用 preg_replace 用数组中的字符串替换子字符串? (PHP)

我有一个包含这些值的数据数组:Array([id]=>1[myid]=>9[date]=>2014-01-30[user]=>17[reason]=>sometexthere...)这个字符串包含引用数据数组索引的数字:$columns='(0)as"id",(1)as"myid",(2)as"date",(3)as"user",(4)as"reason"';是否可以更改括号中的数字,包括将括号中的数字更改为数组中的适当值?我知道如何使用(string)preg_replace((array)$patterns,(array)$replacements,(string)$subject