Manipulating SharePoint list items with PHP

For long time I’ve been playing around in my head with the idea to be able to connect to SharePoint Web Services with some third-party tools. Finaly I googled a bit and found quite few articles about it. I liked the most the one from http://davidsit.wordpress.com.

I am also attaching the the code for php version 5.3 with built in SOAP support. The only thing I added are the HTML tags and UTF-8 charset in order to display slovenian characters properly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Manipulating SharePoint list items with PHP</title>
</head>
<?php
//Authentication details
$authParams = array('login' => 'yourUsername', 'password' => 'yourPassword');

/* A string that contains either the display name or the GUID for the list.
 * It is recommended that you use the GUID, which must be surrounded by curly
 * braces ({}).
 */

$listName = "TempList";
$rowLimit = '150';

/* Local path to the Lists.asmx WSDL file (localhost). You must first download
 * it manually from your SharePoint site (which should be available at
 * yoursharepointsite.com/subsite/_vti_bin/Lists.asmx?WSDL)
 */

$wsdl = "http://localhost/_vti_bin/Lists.asmx?WSDL";

//Creating the SOAP client and initializing the GetListItems method parameters
$soapClient = new SoapClient($wsdl, $authParams);
$params = array('listName' => $listName, 'rowLimit' => $rowLimit);

//Calling the GetListItems Web Service
$rawXMLresponse = null;
try{
    $rawXMLresponse = $soapClient->GetListItems($params)->GetListItemsResult->any;
}
catch(SoapFault $fault){
    echo 'Fault code: '.$fault->faultcode;
    echo 'Fault string: '.$fault->faultstring;
}
echo '<pre>' . $rawXMLresponse . '</pre>';

//Loading the XML result into parsable DOM elements
$dom = new DOMDocument();
$dom->loadXML($rawXMLresponse);
$results = $dom->getElementsByTagNameNS("#RowsetSchema", "*");

//Fetching the elements values. Specify more attributes as necessary
foreach($results as $result){
    echo $result->getAttribute("ows_LinkTitle")."<br/>";
}
unset($soapClient);
?>
<body>
</body>
</html>

In the article from David Dudok de Wit you will also find a solution for older PHP versions. You just have to include nusoap.php library