使用php替换包含的html文件中的blob url和其他字符串

时间:2017-12-31 10:23:49

标签: php string replace

我有2个文件。一个是 test.html ,另一个是 main.php

test.html

main

main.php

中的第二个
<div class=\"col-sm-5 blind-s4\">
          <div class=\"blind-box \">
                <img src="blob:http://example.com/aea01f28-dcd0-41c2-80fa-4f021fe9d40d" class="new-img">
                </div>  
        </div>    

在此,我想将<div class="full-html" id="full-html"> <?php include("test.html");?> </div> 中的所有\"替换为test.html

(2)我想用新图像名称

替换所有以blob开头的内容
"

  ie:blob:http://example.com/aea01f28-dcd0-41c2-80fa-4f021fe9d40d with new.img

我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

试试这个:

function replaceSlash($content) {
  return str_replace('\"', '"', $content);
}

ob_start('replaceSlash');
include('test.html');
ob_end_flush();

Credits

答案 1 :(得分:1)

您可以使用file_get_contentsstr_replace

像那样

$myFile = file_get_contents('text.html');
$newFile = str_replace('\"', '"', $myFile);

然后你可以用echo

编写内容
echo $newFile;

更新

替换blob你应该使用regexp

str_replace(/src="blob:[^"]*/, 'src="new.img"', $newFile);