Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

salathe last won the day on March 7 2019

salathe had the most liked content!

About salathe

Contact Methods

  • Website URL
    http://cowburn.info

Profile Information

  • Gender
    Male
  • Location
    Edinburgh, Scotland

Recent Profile Visitors

4,750 profile views

salathe's Achievements

Member

Member (2/5)

40

Reputation

  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.
×
×
  • 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.