我在服務器之間傳輸數據,並需要更改我們的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