I am transferring data between servers, and need to change some links in our wiki database. I wrote a quick script that should be able to do this no problem. But When I run it, the if($datacount)
condition never runs. This is probably something simple that I'm missing, but I can't see what the issue is.
$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++;
}
Thanks! EDIT
When I remove the $datacount
condition, this is my output
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
? (echo it together with$datacount
).$info
alongside$datacount
I get something like Length: 144,$info
=String(144){'onehundred44 characters of stuff'}, so there is content inside$info
and$count
is not always equal to 0.