我在服务器之间传输数据,并需要更改我们的wiki数据库中的一些链接。我写了一个快速的脚本,应该能够做到这一点没有问题。但是当我运行它时,if($datacount)
条件从不运行。这可能很简单,我错过了,但我看不出是什么问题。数据库字符串在postgresql比较不识别字符串长度
$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
'$ string'的内容是什么? (与'$ datacount'一起回显)。 – 2013-03-19 15:00:00
$ string只是一些随机文本。这很奇怪,因为当我在'$ datacount'旁边回显'$ info'时,我得到了如下长度:144,'$ info' = String(144){'one441 characters of stuff'},所以'$ info'内有内容'$ count'并不总是等于0. – Ryan 2013-03-19 15:25:40