我拼凑了足够的代码来查找和替换大量文本中特定短语之间的文本,但是我只是挂断了只替换该文本。下面的代码找到它并替换整个非常长的字符串而不是仅仅想要定位的部分。例如,如果想要改变" WRONG TAG =等等等等等等等等。在"苏西骑着自行车走在街上 WRONG TAG =等等等等等等等等#34;等于" Susie骑着自行车沿着街道行驶 RIGHT TAG BLAH BLAH BLAH "现在我把整个事情擦掉,只留下"正确的标签BLAH BLAH BLAH"
$text = mysqli_query($conn, "Select body from ReplaceTest");
$imageId = 'new tag = 787654323';
$search = "/[^$wrongTag](.*)[^<\/]/";
$replace = "$id";
$string = "<wrongTag:id=\" blah blah blah />";
$newText = preg_replace($search,$replace,$string);
$update = mysqli_query($conn, "UPDATE T1
SET body = '$newText'");
答案 0 :(得分:0)
尝试使用:
$newText = preg_replace('/<$wrongTag([^>]+)/', "<$rigthtag$1", $string);