我正在服务器之间传输数据,并且需要更改我们 wiki 数据库中的一些链接。我写了一个快速脚本,应该能够做到这一点没问题。但是当我运行它时,if($datacount)
条件永远不会运行。这可能是我缺少的一些简单的东西,但我看不出问题出在哪里。
$dbconn = pg_connect("host= localhost port=5432 dbname=wiki user=user password=password");
$sql = "SELECT old_text FROM wiki_public.pagecontent LIMIT 10";
$go = pg_query($dbconn,$sql);
$i=0;
$string = 'sometext';
while($data = pg_fetch_assoc($go)) {
$info = $data['old_text'];
$count = strlen($string);
$datacount = strlen($info);
echo "Length: ".$datacount."<br/>";
if($datacount != 0) {
$position = strpos($string,$info);
if($position !== false) {
echo "The string ".$string." was found in row ".$i." and exists at position ".$position."The original content was: ".substr($info, $position,$count)."<br/>";
}
}
$i++;
}
谢谢! 编辑
当我删除$datacount
条件时,这是我的输出
Length: 0
Warning: strpos(): Empty delimiter in D:\www\import\linksupadte.php on line 12
Length: 12
Length: 0
Warning: strpos(): Empty delimiter in D:\www\import\linksupadte.php on line 12
Length: 31
Length: 31
Length: 0
Warning: strpos(): Empty delimiter in D:\www\import\linksupadte.php on line 12
Length: 444
Length: 1614
Length: 153
Length: 125