草庐IT

Search-and-replace

全部标签

php - 无法使用 str_replace 删除特殊字符

我有一个关于str_replace的小问题。我有一个带有破折号(-)的字符串,如下所示:Iwanttoremove-thedashhtml输出是Iwanttoremovethe–thedash我想这样做:$new_string=str_replace('-','',$string);我尝试用html_entity_decode解析字符串,用htmlspecialchars解析要删除的字符,但没有任何结果。我做错了什么?-编辑-这是我的脚本的完整代码:$title='SuperMarioGalaxy2-DebutTrailer';//FetchedfromtheDB,inth

php - 向多个收件人发送电子邮件 - 抄送 : and Bcc: in php

这个程序正在运行,但是如何发送多个CC和BCC。for($i=0;$i\r\n";$headers.="Reply-To:\r\n";$hedders.="cc:\r\n";$headers.="Bcc:\r\n";$headers.="X-Mailer:PHP4.x";$sendbcc=$snteadd[$i].",";$sendbcc.=$sendCC.",";$sendbcc.=$sendBCC;if($jvl!=$i){$toinfo.=",";}if($snteadd[$i]!=""){$result=mail($sendbcc,$subjt,$mess,$headers);

php - preg_replace() 模式删除 php 中的括号和内容

我想使用preg_replace()删除括号及其内容,但我无法在模式中使用惰性(非贪婪),因为结束括号是结束字符,括号之间的文本始终是一个随机字符长度,可以包含数字、下划线和连字符。代码-$array=array("Textiwanttokeep(txttoremove)","Randomtxt(somemorerandomtxt)","Keepthis(remove)","Ilikebananas(txt)");$pattern="@pattern@";foreach($arrayas$new_txt){$new_outputs.=preg_replace($pattern,'',$

PHP: preg_replace (x) 发生?

我最近问了一个类似的问题,但没有得到明确的答案,因为我太具体了。这个更广泛。有人知道如何替换正则表达式模式中出现的(x)吗?示例:假设我想替换字符串中第5次出现的正则表达式模式。我该怎么做?这是模式:preg_replace('/{(.*?)\|\:(.*?)}/','替换',$this->source);@anubhava请求示例代码(最后一个功能不起作用):$sample='blahasadaasdas{load|:title}stevejobs{load|:css}windowsapple';$syntax=newsyntax();$syntax->parse($sample);

PHP preg_replace - www 或 http ://

真正坚持看似简单的事情。我有一个聊天框/shoutbox,其中可能输入了任意URL。我想找到每个单独的URL(以空格分隔)并将其包装在标签中。示例:Harryyou'reahttp://google.comwizard!=Harryyou'rea$lhttp://google.com$lwizard!示例:Harryyou'reahttp://www.google.comwizard!=Harryyou'rea$lhttp://www.google.com$lwizard!示例:Harryyou'reawww.google.comwizard!=Harryyou'rea$lwww.go

php - preg_replace 匹配但不替换

在下面的代码中,我尝试获取一些文本并在其周围包裹一个htmlanchor:$d="hello,there,how,are,you";$d=preg_replace("/[a-zA-Z]+/","$1",$d);它正确地识别了每个单词并用替换文本替换了每个单词但是它没有将匹配的单词放入字符串中,它只是将其留空。我在PHP5上。我错过了什么?提前致谢。 最佳答案 您忘记捕获匹配项:$d="hello,there,how,are,you";$d=preg_replace("/([a-zA-Z]+)/","$1",$d);//^^youfo

php in_array() 或 array_search() 不工作

这个问题在这里已经有了答案:PHPin_arrayisn'tfindingavaluethatisthere(3个答案)关闭9年前。我正在使用一个简单的php脚本来查找数组中的元素,例如$restricted=array('root/base','root2');print_r($restricted);if(array_search('root/base',$restricted)){echo"1";}else{echo"0";}但我总是得到以下输出Array([0]=>root/base[1]=>root2)0这意味着array_search无法在给定数组中找到元素。任何人都可以阐

php - Gmail fsockopen() : SSL operation failed error with Codeigniter and XAMPP

Errormessage1:Message:fsockopen():SSLoperationfailedwithcode1.OpenSSLErrormessages:error:14090086:SSLroutines:ssl3_get_server_certificate:certificateverifyfailedFilename:libraries/Email.phpLineNumber:1962Errormessage2:Message:fsockopen():FailedtoenablecryptoErrormessage3:Message:fsockopen():unab

php - 如何删除 https ://from URL and insert http://instead of it in string in PHP?

首先,我需要检查URL字符串,如果URL的协议(protocol)是https,那么我需要替换PHP中的http。所以这个php函数的输入和输出必须是这样的:Input->https://example.com/example/https.phpOutput->http://example.com/example/https.phpInput->http://example.com/example/https.phpOutput->http://example.com/example/https.php 最佳答案 这将确保它位于字符

php - preg_replace http 为 https

简单地说,我需要检查变量$url中的字符串是否是一个简单的http,如果是,将其替换为https-但我无法让它工作-任何想法:$url="http://www.google.com";//examplehttpurl##$url_replaced=preg_replace('#^http://#','https://',$url);//replacehttpwithhttps##干杯! 最佳答案 为什么不用str_replace?$url="http://www.google.com";//examplehttpurl##$url=