是否可以通过搜索特定表达式并仅更改此表达式来更新表中的文本字段,我的意思是通过搜索表达式然后删除此表达式并将新表连接到文本的其余部分来进行更新?
示例
this is a HTML text....<img src="path/to/my/image/empty_gif.gif" />.......html
如何grep img表达式来提供新的图像路径? 这就是我如何连接新文本
UPDATE TABLE_NAME SET FIELD = CONCAT('expression ',FIELD) WHERE CONDITION;
但如何删除前一个?
答案 0 :(得分:0)
<?php
function get_between_tags($tag1, $tag2, $string) {
$outdata='';
if (eregi("$tag1(.*)$tag2", $string, $out)) {
$outdata = $out[1];
}
return $outdata;
}
$res = mysql_query("SELECT FIELD FROM TABLE WHERE CONDITION", $mysql_conn);
while ($row = mysql_fetch_array($res))
{
$result=get_between_tags("Start of the text I want to find","End",$row['FIELD']);
mysql_query("UPDATE TABLE SET FIELD= replace(FIELD,'".$result."','new text') WHERE CONDITION");
}
?>