Porting Perl to PHP - and working with DOM XML
Hello,
I'm primarily a Perl Hacker who has worked on and off with PHP over the years (PHP/FI, PHP3, PHP4) - and I now find myself once again workign with PHP (4.3). I work for an online payments company and we provided integration scripts to our merchants - currently we have ASP, CF, and Perl, But, as you might expect, we have demand for PHP as well. Being the one with some PHP experience I'm the one doing the work. Since I did the port into Perl I know that codebase the best, so I'm using that as my starting point. And, for the most part, the syntax changes aren't a problem.
However, it appears that you can't do things in one step in PHP that you can in Perl. For example:
$xpath = "//CurrencyTable/CurrencyShift[\@number= '" . $currencyNumber . "']";
if (($domCurrency->findnodes($xpath))[0]->h asAttribute("name")) {
...
For PHP you have to break that statement down:
$test = $domCurrency->get_elements_by_tagname($x path);
if ($test[0]->has_attribute("name")) {
PHP isn't happy if I try something like
if (($domCurrency->get_elements_by_tagname( $xpath))[0]->has_attribute("name")) {
Please, correct me if I'm wrong. :-) It just seems like it doesn't allow you to directly reference an element from a method that returns an array.
I've tried a number of different things - wrapping various bits in (), {}. [], etc. All that does is change the error that I get. I've tried finding an answer in the docs, but searching didn't help and skimming 4k+ pages wasn't any better. :-) What I have seen in the docs makes me think that I'm right - I can't do this in one step. But before I resign myself to fate, I thought I'd ask the people who know more than I. :-)
I'm primarily a Perl Hacker who has worked on and off with PHP over the years (PHP/FI, PHP3, PHP4) - and I now find myself once again workign with PHP (4.3). I work for an online payments company and we provided integration scripts to our merchants - currently we have ASP, CF, and Perl, But, as you might expect, we have demand for PHP as well. Being the one with some PHP experience I'm the one doing the work. Since I did the port into Perl I know that codebase the best, so I'm using that as my starting point. And, for the most part, the syntax changes aren't a problem.
However, it appears that you can't do things in one step in PHP that you can in Perl. For example:
$xpath = "//CurrencyTable/CurrencyShift[\@number=
if (($domCurrency->findnodes($xpath))[0]->h
...
For PHP you have to break that statement down:
$test = $domCurrency->get_elements_by_tagname($x
if ($test[0]->has_attribute("name")) {
PHP isn't happy if I try something like
if (($domCurrency->get_elements_by_tagname(
Please, correct me if I'm wrong. :-) It just seems like it doesn't allow you to directly reference an element from a method that returns an array.
I've tried a number of different things - wrapping various bits in (), {}. [], etc. All that does is change the error that I get. I've tried finding an answer in the docs, but searching didn't help and skimming 4k+ pages wasn't any better. :-) What I have seen in the docs makes me think that I'm right - I can't do this in one step. But before I resign myself to fate, I thought I'd ask the people who know more than I. :-)
