DOMDocument() constructor

software development

#1

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?


#2

php4 is default in shell.

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

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

Maximum Cash Discount on any plan with MAXCASH


#3

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


#4

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: …

Maximum Cash Discount on any plan with MAXCASH


#5

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.