I want to do some stuff in some ms word documents using PHP (mostly search-replace), and I've discovered the COM class. But I have a question (because I'm also relative new on PHP), how can I found all methods related to word for example:
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;
How should I now about ActiveDocument, Bookmarks, Range...etc. Is there any way to have a list with all this?
To have autocomplete (InteliSense) you need a PHP class model and a good IDE. This will make your work much much easier.
One of the best IDE's I have come acrross is PHP Tools for Visual Studio. Look for it in the Visual Studio plugin gallery or in the Devsense website. You can use Visual Studio for FREE with the community edition.
To generate a PHP based class model you can either use the COM built in function:
com_print_typeinfo ( object $comobject [, string $dispinterface [, bool $wantsink = false ]] )
Or the NetPhp component (this link is to a step by step example with Word Interop) that will dump all types inside the binary to a complete PHP based class model:
http://www.drupalonwindows.com/en/blog/php-com-class-consuming-net-php
You can also use NetPhp to directly consume the OpenXML binaries and manipulate Word documents without Interop:
http://www.codeproject.com/Tips/994905/Edit-Word-Documents-using-OpenXML-and-Csharp-Witho
Related
I am trying to use Microsoft's Speech Platform 11 through PHP's DOTNET object
https://msdn.microsoft.com/en-us/library/jj127858.aspx
The platform should be instantiated as follows
$platform = new DOTNET("assembly-name", "Microsoft.Speech.Recognition");
But how to retrieve the assembly name for Speech Platform 11? (to replace "assembly-name" in the initialization call)
I have tried several assembly names by... guesswork, obviously with no luck.
The initialization error being thrown
Failed to instantiate .Net object [CreateInstance] [0x80070002] The system cannot find the file specified
UPDATE
With the following code, I was able to get PHP to find and use the assembly
$full_assembly_string = 'Microsoft.Speech, Version=11.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35';
$full_class_name = 'Microsoft.Speech.Recognition.SpeechRecognitionEngine';
$interface = new DOTNET($full_assembly_string, $full_class_name);
However, there's a new roadblock:
Failed to instantiate .Net object [Unwrapped, QI for IDispatch] [0x80004002] No such interface supported
At first glance it seems it has to do with COM visibility. But if for any reason the class isn't visible to COM (and it seems odd), how to change this? Is it even possible?
Not tested. Just another guess.
According to the Microsoft Speech Platform SDK 11 Docs:
https://msdn.microsoft.com/en-us/library/microsoft.speech.recognition.speechrecognitionengine.aspx
i would give this a try:
"assembly" Microsoft.Speech
"classname" Microsoft.Speech.Recognition.SpeechRecognitionEngine
Microsoft.Speech.Recognition is only the namespace
$sre = new DOTNET(
'Microsoft.Speech',
'Microsoft.Speech.Recognition.SpeechRecognitionEngine'
);
Methods are documented here: https://msdn.microsoft.com/en-us/library/microsoft.speech.recognition.speechrecognitionengine_members(v=office.14).aspx#Anchor_2
I am just getting started with graph databases. I would like to talk to them in a PHP application. In particular, I am looking at OrientDB, mainly because of its licensing benefits and features over neo4j.
What is the recommended way to interact with OrientDB within PHP? Is there a generalized framework like tinkerpop for the PHP world?
I would like to query my graphs using mainly gremlin and a bit of OrientDB's extended SQL (only if necessary).
I know there are 2 php connectors: Orient and OrientDB-PHP, but have not tried them yet. Has anyone had any experiences with them? What are the pros and cons? I would of course prefer something like tinkerpop for PHP if it exists, but if it doesn't a library geared towards OrientDB is fine too.
I'm Alex, I actually wrote the biggest part of the codebase for Orient (the php library).
In PHP, currently, there is no thing like tinkerpop but I think you should be able to kickstart with Orient. Using it its extremely simple:
<?php
namespace Congow\Orient;
use Congow\Orient\Binding\HttpBinding;
use Congow\Orient\Binding\BindingParameters;
require __DIR__.'/../autoload.php';
$parameters = BindingParameters::create('http://admin:admin#127.0.0.1:2480/friends');
$binding = new HttpBinding($parameters);
$response = $binding->query('select from friends where any() traverse(0,1) ( #rid = #5:3 ) and #rid <> #5:3');
$friends = $response->getResult();
foreach ($friends as $friend) {
echo $friend->name, "\n";
}
Instead of writing the query from scratch you can also use the query builder:
$query = new Select(array('myClass'));
$query->orderBy("name ASC", false);
echo $query->getRaw() // SELECT FROM myClass ORDER BY name ASC
You could have a look at the tests of the library, or at the mini-samples in the example directory.
We are slowly keep going on with the development, so you find a few resources here: http://odino.org/blog/categories/orientdb/
Cheers,
I know It's been a while but I wanted to point out that you can use the Tinkerpop stack in PHP via available drivers.
These will allow you a certain level of abstraction over the underlying database you choose -- thus allowing you to switch DBs when needed (Neo4j, OrientDB, Titan, etc.).
TinkerPop 3
You can use Gremlin server (new name for rexster) via the php driver available:
gremlin-php check this tutorial
Tinkerpop 2 (no longer maintained)
You can use the Rexster server from the stack via the php drivers available:
rexpro-php check this article
Doolittle
rexpro-php-driver (PHP ext.)
I would like to create a web service in PHP which can be consumed by different consumers (Web page, Android device, iOS device).
I come from a Microsoft background so am confortable in how I would do it in C# etc. Ideally I would like to be able to provide a REST service which can send JSON.
Can you let me know how I can achieve this in PHP?
Thanks
Tariq
I developed a class that is the PHP native SoapServer class' REST equivalent.
You just include the RestServer.php file and then use it as follows.
class Hello
{
public static function sayHello($name)
{
return "Hello, " . $name;
}
}
$rest = new RestServer(Hello);
$rest->handle();
Then you can make calls from another language like this:
http://myserver.com/path/to/api?method=sayHello&name=World
(Note that it doesn't matter what order the params are provided in the query string. Also, the param key names as well as the method name are case-insensitive.)
Get it here.
I would suggest you go for Yii it is worth of learning. You can easily establish it in this.
Web Service. Yii provides CWebService and CWebServiceAction to simplify the work of implementing Web service in a Web application. Web service relies on SOAP as its foundation layer of the communication protocol stack.
Easiest way in PHP is to use GET/POST as data-in and echo as data-out.
Here's a sample:
<?php if(empty($_GET['method'])) die('no method specified');
switch($_GET['method']){
case 'add': {
if(empty($_GET['a']) || empty($_GET['b'])) die("Please provide two numbers. ");
if(!is_numeric($_GET['a']) || !is_numeric($_GET['b'])) die("Those aren't numbers, please provide numbers. ");
die(''.($_GET['a']+$_GET['b']));
break;
}
}
Save this as test.php and go to http://localhost/test.php?method=add&a=2&b=3 (or wherever your webserver is) and it should say 5.
PHP does have native support for a SOAP server ( The SoapServer class manual shows it) and I've found it pretty simple to use.
Creating a REST style API is pretty easy if you use a framework. I don't want to get into a debate about which framework is better but CakePHP also supports output as XML and I'm pretty sure others will as well.
If you're coming from a Microsoft background just be careful about thinking about "datasets". They are a very specific Microsoft thing and have been a curse of mine in the past. It's probably not going to be an issue for you, but you may want to just see the differences between Microsoft and open implementations.
And of course PHP has a native json_encode() function.
You can check out this nice RESTful server written for Codeigniter, RESTful server.
It does support XML, JSON, etc. responses, so I think this is your library.
There is even a nice tutorial for this on the Tutsplus network -
Working with RESTful Services in CodeIgniter
You can also try PHP REST Data Services https://github.com/chaturadilan/PHP-Data-Services
You can use any existing PHP framework like CodeIgniter or Symfony or CakePHP to build the webservices.
You can also use plain PHP like disscussed in this example
Is it possible to use Zend Dom Query without Zend Framework?
If yes: Where to download Zend Dom Query and how to use it without Zend Framework?
You can pull out the separate ZF files using some package managers like this one, which will tell what files do you need and will compress them for you. Zend_Dom_Query requires only
Zend/Dom/Query.php
Zend/Dom/Query/Css2Xpath.php
Zend/Dom/Query/Result.php
Zend/Dom/Exception.php
Zend/Exception.php
Anyhow, it's available for download. If there is an urgent need - there are lot of other tools like this one not only for ZF.
The classes in Zend are not meant to be used standalone - is there a reason you cannot have the whole of ZF available but only use Zend_Dom_Query?
Failing that you can get the folder
/library/Dom/
And take it out of the ZF folder, you'll then need to look for any depenancies, having a quick look you will also need:
/library/Exception/Exception.php
Give that a go, let us know how it goes....
I assume by 'without Zend Framework' you mean without using Zend Framework's MVC components. You can use any component of Zend Framework in isolation; it is a glue framework.
Download the library and extract it into your project's library folder or PHP include path. It should then be roughly as simple as the following:
<?php
require_once 'Zend/Dom/Query.php';
$query = new Zend_Dom_Query(....);
It seems to me this approach doesn't work with Zend Framework 2, I don't know why...
You can use zendframework/zend-dom as a standalone component. It has no external dependencies, which means that it doesn't need another Zend component or other library to work.
Alternatively, you could also use a library that is totally unrelated to Zend, like tburry/pquery or my own PHPPowertools/DOM-Query. Both libraries serve the same purpose as zendframework/zend-dom, but syntax is different and HTML5 support may vary for each library.
Example :
This example illustrates how you'd load an HTML string and query for .foo .bar a, with each of these three libraries :
Using zendframework/zend-dom you'd do this :
use \Zend\Dom\Query;
$dom = new Query($htmlcode);
$results = $dom->execute('.foo .bar a');
Using tburry/pquery, you'd do this :
use \pQuery\pQuery
$dom = pQuery::parseStr($htmlcode);
$dom->query('.foo .bar a');
Using PHPPowertools/DOM-Query, you'd do this :
use \PowerTools\DOM_Query
$H = new DOM_Query($htmlcode);
$s = $H->select('.foo .bar a');
Pick your poison!
I'm using the native SOAP class in PHP 5, having changed from NuSOAP as the native class is faster (and NuSOAP development seems to have ceased). However the PHP 5 SOAP lacks the ability to generate WSDL.
Has anyone experience of generating WSDL in PHP? If so, please recommend your preferred method.
Thanks.
Stuart,
If you or anyone else is looking for a solution to this problem here's what I did.
First get this script: http://www.phpclasses.org/browse/download/zip/package/3509/name/php2wsdl-2009-05-15.zip
Then look at its example files. After that I just sliced it the way I needed because I'm using codeigniter:
function wsdl(){
error_reporting(0);
require_once(APPPATH."/libraries/WSDLCreator.php"); //Path to the library
$test = new WSDLCreator("Webservice", $this->site."/wsdl");
//$test->includeMethodsDocumentation(false);
$test->addFile(APPPATH."/controllers/gds.php");
$test->addURLToClass("GDS", $this->site);
$test->ignoreMethod(array("GDS"=>"GDS"));
$test->ignoreMethod(array("GDS"=>"accessCheck"));
$test->createWSDL();
$test->printWSDL(true); // print with headers
}
That it, your all done.
Btw, I'm using SoapServer and SoapClient in php5+
You can try these options:
- https://code.google.com/p/php-wsdl-creator/ (GPLv3)
- https://github.com/piotrooo/wsdl-creator/ (GPLv3)
- http://www.phpclasses.org/package/3509-PHP-Generate-WSDL-from-PHP-classes-code.html (BSD like)
The first one might be your best option if the licence fits your project.
Generating a WSDL on the fly is not something that happens very often - it would tend to raise a few questions about the stability of your service!
Zend Studio can generate a WSDL from a PHP class, and there are a few other similar tools.
If you do need to generate the WSDL dynamically, take a look at Zend Framework library: Zend_Soap_AutoDiscover
Zend_Soap_AutoDiscover is a good alternative to NuSOAP. But, you can also create the WSDL file from scratch which can be very complicated and error prone. To ease this process, you can use an IDE to generate the WSDL file for your PHP functions and pass it as a parameter to your PHP SoapServer class. Check out the complete tutorial on How to generate wsdl for php native soap class