Jump to content

salathe

Staff Alumni
  • Content count

    1,828
  • Joined

  • Last visited

  • Days Won

    2

salathe last won the day on March 6 2013

salathe had the most liked content!

Community Reputation

38 Good

About salathe

  • Rank
    Badger

Contact Methods

  • Website URL
    http://cowburn.info

Profile Information

  • Gender
    Male
  • Location
    Edinburgh, Scotland
  1. salathe

    XML parsing

    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. salathe

    php frameworks

    Unfortunately, I can't. P.S. Maybe you're too new to realise that my previous P.S. was sarcastic in nature.
  3. salathe

    php frameworks

    Were you really hoping for us to come along and say, "Easy, framework XYZ is best."? Without context, it is not even possible to steer towards frameworks that might be useful to you, never mind the best of those! Is it the best at washing the dishes? Please, if you're going to make claims of suitability then at least be informative with it. P.S. quit spamming.
  4. salathe

    php An or A function.

    You could also replace the return statement in rajivgonsalves' function with the similarly functioning: return strspn(strtolower($word[0]), 'aeiou') ? 'an' : 'a';
  5. salathe

    php An or A function.

    thorpe, the OP wants to be able to determine whether "an" or "a" should preceed a word. For example given the words apple, banana, orange the correct choices would be an, a, an respectively.
×

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.