substr_replace大字符串中出现的所有内容

时间:2013-10-07 16:54:50

标签: php replace substring

我有以下代码,我试图在$ query变量中做一个正则表达式替换,我需要用“Bye”替换所有出现的“Hello”。这段代码有什么问题?

<?php

ini_set("default_socket_timeout", 116000);

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://www.mysite.com.br/index.php?option=com_xxxx&format=xml');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);


if (strlen($query) > 95000){
echo "OK";
substr_replace ($query ("hello","bye",0));
file_put_contents('/home/myuser/mysite.com/xml/file.xml',$query);
} 
else 
{
echo "Error";
}

?>

1 个答案:

答案 0 :(得分:1)

str_replace实际上是您正在寻找的命令;

$query = str_replace ("hello","bye",$query);