草庐IT

str_replacing

全部标签

php - preg_replace 模式和主题数组返回空数组

我想要一种从$keywords中删除$badwords元素的简单方法。我有什么(举个例子)$keywords=array('sebastian','nous','helene','lol');//itcouldbeanythinginfact$badwords=array('nous','lol','ene','seba');//arrayfullofstopwordsthatIwon'twritehere$filtered_keywords=array_filter(preg_replace($badwords,'',$keywords),'strlen');print_r($fil

php - preg_replace 在省略时插入默认值

我正在尝试为preg_replace处理一些正则表达式,当它不在主题中时,它会插入一个默认的key="value"。这是我所拥有的:$pattern='/\[section([^\]]+)(?!type)\]/i';$replacement='[section$1type="wrapper"]';我想让它变成:[sectiontitle="Thisisthetitle"]进入:[sectiontitle="Thisisthetitle"type="wrapper"]但是当有值的时候,我不希望它匹配。这意味着:[sectiontitle="Thisisthetitle"type="ful

URL 查询的 PHP parse_str 返回键名中包含 'amp' 的数组键

环境:主机(JustHost)上测试站点上的Wordpress(最新),PHP版本为5.4.43。在URL查询中使用parse_str,生成的数组返回amp;keyname的数组键名。示例代码:$querystring="ie=UTF8&qid=1468851514&sr=8-1&keywords=there&tag=sitename-20";parse_str($querystring,$queryarray);echo"";print_r($queryarray);echo"";返回Array([ie]=>UTF8[amp;qid]=>1468851514[amp;sr]=>8-1

php - 如何从右到左str_split字符串?

假设我有一个数字10000,我想将它从右到左分成2个字符,得到类似这样的数组[0]=>1,[1]=>00,[2]=>00。str_split($var,2);是否有可能? 最佳答案 必须有更简单的方法,但您可以使用类似的方法:array_map("strrev",array_reverse(str_split(strrev(10000),2)));[0]=>1[1]=>00[2]=>00strrev()-反转字符串str_split()-将字符串转换为数组array_reverse()-返回一个元素反向的数组订单array_map(

php - 如何在一个 preg_replace() 中将所有非单词字符和多个空格更改为 ' ' 然后将所有空格更改为 '-'

我想在以下条件下更改图像名称所有非单词字符变成空格,然后所有空格变成-表示如果我的图像名称是:HelloMynameis'Kh@n"Mr..Khan"那么它应该被更改为Hello-My-name-is-kh-n-mr-Khan.我需要分两步使用下面,$old_name='HelloMynameis\'Kh@n"Mr.Khan';$space_name=preg_replace('/\W/','',$old_name);$new_name=preg_replace('/\s+/','-',$space_name);echo$new_name//returnsHello-My-name-i

php str_ireplace 不丢失大小写

是否可以在不破坏原始外壳的情况下运行str_ireplace?例如:$txt="HelloHowAreYou";$a="are";$h="hello";$txt=str_ireplace($a,"".$a."",$txt);$txt=str_ireplace($h,"".$h."",$txt);一切正常,但结果输出:[hello]How[are]You代替:[Hello]How[Are]You(方括号是彩色背景)谢谢。 最佳答案 您可能正在寻找这个:$txt=preg_replace("#\\b($a|$h)\\b#i","$1",

php - 将 preg_replace() 替换为 preg_replace_callback()

这个问题在这里已经有了答案:Replacepreg_replace()emodifierwithpreg_replace_callback(3个答案)关闭3年前。$source=preg_replace('/&#(\d+);/me',"utf8_encode(chr(\\1))",$source);上面的代码给出了弃用的警告。Deprecated:preg_replace():The/emodifierisdeprecated,usepreg_replace_callbackinsteadin如何将preg_replace()替换为preg_replace_callback()?

php - PHP的str_replace()中,双反斜杠是什么意思?

我想删除所有\r\n\r\n这很容易,所以我写道:str_replace(array("\r","\n"),"",$text);但我看到了这一行:str_replace(array("\r","\n","\\r","\\n"),"",$text);我想知道双反斜杠是什么意思\\r和\\n。 最佳答案 \为转义字符,用于转义后面的字符。在"\n"中,反斜杠转义n,结果将是一个换行符。在"\\n"中,第一个反斜杠转义了第二个反斜杠并且n保持原样,所以结果是一个包含\n(字面意思)。参见PHPofficialdocumentation>S

字符串和引号之间的 PHP preg_replace

我有一个包含以下内容的配置文件;[settings];absolutepathtothetempdir.Ifemptythedefaultsystemtmpdirectorywillbeusedtemp_path="";ifsettotrue:detectsifthecontentsareUTF-8encodedandifnotencodesthem;ifsettofalsedonothingencode_to_UTF8="false";defaultdocumentlanguagelanguage="en-US";defaultpapersizepaper_size="A4"[lic

php - 警告 : preg_replace() [function. preg-replace]:编译失败:在偏移量 1 处没有可重复的内容

有人可以帮助调试这个错误吗?Warning:preg_replace()[function.preg-replace]:Compilationfailed:nothingtorepeatatoffset1//Generateuidfunctiongen_uid($len=40){$hex=md5("what".uniqid("",true));$pack=pack('H*',$hex);$tmp=base64_encode($pack);$uid=preg_replace("#(*UTF8)[^A-Za-z0-9]#","",$tmp);$len=max(4,min(128,$len)