Php 使用其他URL代码点火器更改URL

Php 使用其他URL代码点火器更改URL,php,html,string,codeigniter,Php,Html,String,Codeigniter,我有一根像 $str="<a href='https://www.google.com'>Google</a>Test url <a href='https://www.twitter.com'>Twitter</a>Sample content <a href='example.com'>Example</a>..... ............................

我有一根像

 $str="<a href='https://www.google.com'>Google</a>Test url
       <a href='https://www.twitter.com'>Twitter</a>Sample content
       <a href='example.com'>Example</a>.....
        ...................................";
$str=“测试url
样本含量
.....
...................................";
我想替换超链接中的URL,如下所示

   $result="<a href='http://my_url.com/https://www.google.com'>Google</a>Test url
            <a href='http://my_url.com/https://www.twitter.com'>Twitter</a>Sample content
            <a href='http://my_url.com/example.com'>Example</a>
            ..................................................
             ...............................";
$result=“测试url
样本含量
..................................................
...............................";

我的意思是,每个url都将是我的web url的一部分。如果可以使用preg_replace(),请帮助我尝试使用
str_replace
like

$arr1 = array('https://www.google.com','https://www.twitter.com','example.com');
$arr2 = array('http://my_url.com/https://www.google.com','http://my_url.com/https://www.twitter.com','http://my_url.com/example.com');
$str="<a href='https://www.google.com'>Google</a>Test url
      <a href='https://www.twitter.com'>Twitter</a>Sample content
      <a href='example.com'>Example</a>";

$newStr = str_replace($arr1 , $arr2 , $str);
echo $newStr;
或者干脆试试看

$newStr = str_replace("href='" , "href='http://my_url.com/" , $str);

url是动态创建的,我不知道它们是什么。这只是一个示例。请考虑我的编辑一次。您只需要使用该动态url创建数组,但我不知道如何将所有url设置为$arr1。因为该字符串包含大量url,请参阅上一个解决方案
$newStr = str_replace("href='" , "href='http://my_url.com/" , $str);