Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. Working with namespaced elements is annoying, with SimpleXML. You can recognise namespaces by xmlns:...="..." attributes, and <foo:name tags. A better option would be to use the DOM family of classes and functions. Here's a basic example that grabs the <ax21:...> elements from your XML and throws them into an array. <?php $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns:getReportTestResponse xmlns:ns="http://webservice.avm.pvads.com"> <ns:return xmlns:ax21="http://webservice.avm.pvads.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:WSReportBean"> <ax21:confidence /> <ax21:dateStamp>12/07/2007</ax21:dateStamp> <ax21:html>adsasdasdsadasd</ax21:html> <ax21:pdsReference /> <ax21:product>AVi (Exterior AND Interior Inspection) - 48hr RUSH</ax21:product> <ax21:sourceData /> <ax21:successful>true</ax21:successful> <ax21:value>168000.0</ax21:value> </ns:return> </ns:getReportTestResponse> </soapenv:Body> </soapenv:Envelope> XML; $document = new DOMDocument; $document->loadXML($xml); $ax21_elements = $document->getElementsByTagNameNS("http://webservice.avm.pvads.com/xsd", "*"); $array = array(); foreach ($ax21_elements as $element) { $array[$element->localName] = trim($element->textContent); } var_dump($array); That will output an array like: array( { ["confidence"]=> string(0) "" ["dateStamp"]=> string(10) "12/07/2007" ["html"]=> string(15) "adsasdasdsadasd" ["pdsReference"]=> string(0) "" ["product"]=> string(50) "AVi (Exterior AND Interior Inspection) - 48hr RUSH" ["sourceData"]=> string(0) "" ["successful"]=> string(4) "true" ["value"]=> string( "168000.0" } That said, there's usually no real need to "convert" XML into an array at all. Instead, work with the DOM objects (here $document, $ax21_elements, and $element are DOM objects).
  2. I've been here for 4 years and have a little over half as many profile views. I guess you're Mr Popular.
  3. Some guidance for the OP about using parse_url() for his particular needs wouldn't go amiss, guys; especially since parse_url() would only go a small way towards resolving the question posed.
  4. Why would you feel safer? strtotime() has a finite list of formats that it will accept, yours is one of them.
  5. $classname = 'class.validator'; function __autoload($classname) { $filename = $classname . '.php'; require_once($filename); } $validator = new Validator; That's not how autoloading works. The idea is what when your code tries to use a class that PHP has not loaded yet, the autoloader function provides the opportunity for your script to load the correct file before PHP finally gives up and barfs out an error. In your script, upon reaching the "new Validator" part, PHP knows that the class has not been loaded yet. You have defined an autoloader so it gets called with the class name: effectively calling __autoload("Validator"). Looking inside your function, hopefully you can see that $filename will become Validator.php, which is not the correct file name to be loading (you wanted class.validator.php). You probably want to make the first line of the function be like $filename = "class." . strtolower($classname) . ".php";
  6. The array_key_exists() function returns whether the array has the specified key, or not. To steal a comment from the manual, "An array in PHP is … a type that associates values to keys." (http://php.net/arrays). In your example, your array has only one value "a" and its key is 0. It looks like the function you really wanted was in_array() (http://php.net/in_array), which returns whether the array as the specified value, or not.
  7. That's right, the <item> elements that you want are not within a namespace so there is no need to register a prefix nor use that prefix in the XPath query. If you decided not to use XPath at all, an alternative would be like: foreach ($entries->channel->item as $entry) …
  8. The three different date parts have the following effect: 2013-05-31 is evaluated: internal date 2013-05-31 (at midnight) +1 months is evaluated: internal date 2013-06-31 (that's right, June 31st) the logic is simply to increment the month number without touching days last day of is evaluated: internal date 2013-06-30 (June only has 30 days) It is only after all of these steps that the date, if it is invalid, is tweaked to become valid. For example, if we didn't have "last day of" then it would have rolled around to July 1st. Aside: in this case, it is not important which order the three parts are written.
  9. It looks fine to me (http://bit.ly/144fHH6); maybe Device Magic is sending something incorrectly?
  10. Why? It looks like you're only trying to make a unique file name; you seem to be over-thinking this problem somewhat. Anyway, if you don't want repetition then something as basic as 1, 2, 3 ... does that.
  11. How large a range of numbers are you looking for, are 2147483648 numbers not enough?
  12. salathe

    forum back

    I don't know what you're talking about, the forum has been fine the last few days.
  13. You're using an old version of PHP (less than 5.3.0) that does not allow the const keyword outside of a class definition. Change them to use define() instead. const REDIRECT_URL = 'INSERT YOUR REDIRECT URL HERE'; // change the above to this: define('REDIRECT_URL', 'INSERT YOUR REDIRECT URL HERE'); There is a very good chance that there are other parts of the code which require PHP 5.3.0 or greater, so these constants might not be the only thing that you need to change to get the script to work on an older version of PHP.
  14. Start here: http://php.net/manual/en/reference.pcre.pattern.posix.php
  15. Is the URL supposed to be http://ACTON.somesite.com/buy-and-sell-Page1ZZisCitySearchtrue ? That seems odd with the ZZ… part, which is why I'd like to check with you.
  16. The LIST command that you're sending via the PHP script is different to that that is expected (and the one you demonstrated with telnet). The PHP script sends: C02 LIST '' '*' When it should send: C02 LIST "" "*" See the difference? Something like the following would suffice: fwrite($fp, 'C02 LIST "" "*"' . "\r\n");
  17. RegisterResponse is already in the http://tempuri.org namespace. You can see that in the document element's opening tag, a prefix is defined (xmlns:ns1="http://tempuri.org"), which is then used for RegisterResponse (ns1:RegisterResponse). I'm with requinix, do you have a functional problem or could you explain in more detail why you want the namespace declared in the RegisterResponse tag?
  18. Nothing wrong at all, except it will print the value for January 1st of the current year. When given to strtotime(), the 2000 is interpreted as a 24-hour time: 8pm. A good way would be something like the following, which uses DateTime::createFromFormat(). $date = DateTime::createFromFormat('!Y', $year)->format('Ymd'); If you're still stuck on PHP 5.2 or lower (I'm sorry!) then mktime() is an alternative. $date = date('Ymd', mktime(0, 0, 0, 1, 1, $year));
  19. It is common to put a filtering and/or monitoring appliance between your employees and the internet. There is also software that can be deployed onto the machines to monitor application usage.
  20. Hi chaps, What happened to the information beside each post with things like the poster's location, age, etc.? Currently it has been whittled down to just the post count, which seems like an odd choice. What's the score? Cheery-byes, Peter
  21. The freelancing forum is over there ---> http://forums.phpfreaks.com/forum/20-php-freelancing/
  22. The comma operator is a very esoteric operator, rarely seen out in the wild. I'm not surprised that you're surprised that it is valid. Its use is discouraged.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.