DOMDocument() constructor

DOMDocument() constructor

Posted by: lachette
Posted on: 2008-11-10 08:51:00

Hi all,

I'm trying to run some php scripts in shell. part of the script needs the dom constructor:

$dom = new DOMDocument();
@$dom->loadHTML($html);

this works from a browser standpoint but when running in shell you get the error:

Warning: domdocument() expects at least 1 parameter, 0 given in

reading the php documentation they use arguments so following the example provided on the documentation:

$dom = new DOMDocument('1.0', 'UTF-8');
@$dom->loadHTML($html);

gives me a new error.
Warning: domdocument() expects parameter 2 to be long, string given

which makes no sense since the documentation clearly states the second one is a string.

further research says that it is a conflict between php4 and php5 being installed at the same time. since dreamhost manages all those installs and i havent done any custom install of php, is there any way to rectify this problem?

Edited by lachette on 11/10/08 09:05 AM (server time).

Re: DOMDocument() constructor

Posted by: sXi
Posted on: 2008-11-10 10:45:00

php4 is default in shell.

To switch to php5 for shell, add the following to .bash_profile

export PATH=/usr/local/php5/bin:$PATH


Re: DOMDocument() constructor

Posted by: lachette
Posted on: 2008-11-10 12:03:00

Thanks for the reply.

So I put that into the shell and then restarted my session. After running phpinfo() it still says its running php 4.4.8

Re: DOMDocument() constructor

Posted by: sXi
Posted on: 2008-11-10 12:10:00

After the edit, you should be receiving returns like the following:

$ which php
/usr/local/php5/bin/php

$ php -v
PHP 5.2.6 (cli) (built: ....


Re: DOMDocument() constructor

Posted by: lachette
Posted on: 2008-11-10 13:31:00

yep, i get those responses back.

still the script bombs out... i ended up putting

#!/usr/local/php5/bin/php

into the top of the file to force it to php5

But I'd really would like it to interpret it as php5 through the bash like you have tried to help me with.

Tags: php scriptsshell