Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中使用str_replace,使用其他SQL条目的超链接更新SQL内容_Php_Mysql_Sql_Str Replace - Fatal编程技术网

在PHP中使用str_replace,使用其他SQL条目的超链接更新SQL内容

在PHP中使用str_replace,使用其他SQL条目的超链接更新SQL内容,php,mysql,sql,str-replace,Php,Mysql,Sql,Str Replace,我正在处理字典类型的SQL表。完成后,我就准备好了PHP脚本,用html超链接标记更新文本。剧本现在很好用。但是,有些词典条目是短语,包含多个单词,因此内容没有与它们关联的正确链接。例如,如果我运行我当前拥有的脚本,它将分解整个定义,并分别链接心脏病和心脏病发作。我想把“心脏病发作”这个词联系起来 关键词:心肌梗死 定义:心脏病发作 有什么建议吗? 这是我目前使用的脚本 $def = $original['def']; $explode_string = explode(" ",$def); $

我正在处理字典类型的SQL表。完成后,我就准备好了PHP脚本,用html超链接标记更新文本。剧本现在很好用。但是,有些词典条目是短语,包含多个单词,因此内容没有与它们关联的正确链接。例如,如果我运行我当前拥有的脚本,它将分解整个定义,并分别链接心脏病和心脏病发作。我想把“心脏病发作”这个词联系起来

关键词:心肌梗死
定义:心脏病发作

有什么建议吗?
这是我目前使用的脚本

$def = $original['def'];
$explode_string = explode(" ",$def);
$explode_count = count($explode_string);
$compare_count = 0;
if($explode_count>0)
{
    while($compare_count<=$explode_count)
    {
        $sql="SELECT word
             FROM dictionary
             WHERE word='{$explode_string[$compare_count]}'";

        $result=mysql_query($sql);
        if(! $result )
        {
          die('Could not get data: ' . mysql_error());
        }
        $row = mysql_fetch_array($result);
        if($row)
        {
            if($explode_string[$compare_count]!="{$original['word']}")
            {
            $replace="<a href=\'http://www.medicresource.com/medicaldictionary/search.php?word=".$explode_string[$compare_count]."\'>{$explode_string[$compare_count]}</a>";
            $def = str_replace($explode_string[$compare_count], $replace, $def);
            }

        }
        ++$compare_count;
    }
}
$update_sql = "UPDATE dictionary SET def='$def' WHERE id='{$original['id']}'";
$def=$original['def'];
$explode_string=explode(“,$def”);
$explode\u count=计数($explode\u字符串);
$compare_count=0;
如果($explode\u count>0)
{

虽然($compare\u count我认为更好的方法是使用foreach

$def = "Heart attack";
$explode_string = explode(" ",$def);
$explode_count = count($explode_string);

if($explode_count>0)
{
    foreach($explode_string as $word)
    {
        $sql="SELECT word
             FROM dictionary
             WHERE word='" . $word . "'";

        $result=mysql_query($sql);
        if(! $result )
        {
          //die will kill the script
          echo('Could not get data from query : ' . $sql . " error: " . mysql_error());
        }
        $row = mysql_fetch_array($result);
        if($row)
        {
            $replace="<a href=\'http://www.medicresource.com/medicaldictionary/search.php?word=". $word ."\'>" . $word ."</a>";
            $def = str_replace($word, $replace, $def);
        }
    }
}
$update_sql = "UPDATE dictionary SET def='$def' WHERE id='" . $original['id'] . "'";
$def=“心脏病发作”;
$explode_string=explode(“,$def”);
$explode\u count=计数($explode\u字符串);
如果($explode\u count>0)
{
foreach($将字符串分解为$word)
{
$sql=“选择单词”
从字典
其中word='“$word.”;
$result=mysql\u查询($sql);
如果(!$result)
{
//死亡会扼杀剧本
echo('无法从查询中获取数据:'.$sql.。错误:'.mysql_error());
}
$row=mysql\u fetch\u数组($result);
如果($行)
{
$replace=“”;
$def=str_replace($word,$replace,$def);
}
}
}
$update_sql=“更新字典集def='$def'其中id='.”$original['id']”;

我认为更好的方法是使用foreach

$def = "Heart attack";
$explode_string = explode(" ",$def);
$explode_count = count($explode_string);

if($explode_count>0)
{
    foreach($explode_string as $word)
    {
        $sql="SELECT word
             FROM dictionary
             WHERE word='" . $word . "'";

        $result=mysql_query($sql);
        if(! $result )
        {
          //die will kill the script
          echo('Could not get data from query : ' . $sql . " error: " . mysql_error());
        }
        $row = mysql_fetch_array($result);
        if($row)
        {
            $replace="<a href=\'http://www.medicresource.com/medicaldictionary/search.php?word=". $word ."\'>" . $word ."</a>";
            $def = str_replace($word, $replace, $def);
        }
    }
}
$update_sql = "UPDATE dictionary SET def='$def' WHERE id='" . $original['id'] . "'";
$def=“心脏病发作”;
$explode_string=explode(“,$def”);
$explode\u count=计数($explode\u字符串);
如果($explode\u count>0)
{
foreach($将字符串分解为$word)
{
$sql=“选择单词”
从字典
其中word='“$word.”;
$result=mysql\u查询($sql);
如果(!$result)
{
//死亡会扼杀剧本
echo('无法从查询中获取数据:'.$sql.。错误:'.mysql_error());
}
$row=mysql\u fetch\u数组($result);
如果($行)
{
$replace=“”;
$def=str_replace($word,$replace,$def);
}
}
}
$update_sql=“更新字典集def='$def'其中id='.”$original['id']”;

您考虑过MySQL全文搜索功能吗?我在MSSQL和排名中使用过,效果很好。您考虑过MySQL全文搜索功能吗?我在MSSQL和排名中使用过,效果很好。