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,910 profile views

salathe's Achievements

Member

Member (2/5)

40

Reputation

  1. This is for PHPMailer 6. This is for PHPMailer 5. Which version do you actually have?
  2. It looks like you're scraping pages from the PHP manual, so taking one of those as an example, the HTML looks like this (super-stripped down for simplicity): <?php $html = '<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <!-- lots more goes here --> </html>'; $dom = new DOMDocument(); $dom->loadHTML($html); var_dump($dom->childNodes->length); foreach ($dom->childNodes as $childNode) { var_dump(get_class($childNode)); } The above outputs the following: int(2) string(15) "DOMDocumentType" string(10) "DOMElement" This shows that the document ($dom) has two child nodes: 1. the document type (<!DOCTYPE html>) and 2. the "html" element. Hope that helps. ?
  3. From the docs: This means that the expression you want to be matched is a single, text (string) value. If you're using a prepared statement, in PHP, with PDO, that means a single question mark (?) or a single ":name" placeholder if you're going for named parameters. A quick demo example: <?php $db = new PDO("sqlite::memory:"); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->exec("CREATE VIRTUAL TABLE example USING FTS5 (a, b)"); $db->exec("INSERT INTO example (a, b) VALUES ('this is an amazing message', 'kittens are lovely')"); $db->exec("INSERT INTO example (a, b) VALUES ('this is a great message', 'dogs are also lovely')"); $db->exec("INSERT INTO example (a, b) VALUES ('this is a message', 'hamsters are best')"); $query = $db->prepare('SELECT * FROM example WHERE example MATCH ?'); $query->execute(array('(b: kittens) OR (a: great)')); $rows = $query->fetchAll(); print_r($rows); The above example outputs the two matching rows. Array ( [0] => Array ( [a] => this is an amazing message [b] => kittens are lovely ) [1] => Array ( [a] => this is a great message [b] => dogs are also lovely ) ) Hope that helps.
  4. A (very) brief note about Countable objects Classes implementing the Countable interface define and implement their own count() method. The DOMNodeList class is one such class. Instances of classes that implement the Countable interface can be passed to the count() function, and their own special count() method gets called. In DOMNodeList's case, that method returns the number of nodes in the list. There is nothing stopping you from calling the count() method on the object (e.g. $myobject->count()) rather than the count() function (e.g. count($myobject)), if that's what you want to do. How the heck am i supposed to count the childNodes? Back to your original question. There are several ways to get the number of nodes in a DOMNodeList (which is what your $dom->childNodes is). 1. $dom->childNodes->length 2. count($dom->childNodes) 3. $dom->childNodes->count()
  5. 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).
  6. I've been here for 4 years and have a little over half as many profile views. I guess you're Mr Popular.
  7. 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.
  8. Why would you feel safer? strtotime() has a finite list of formats that it will accept, yours is one of them.
  9. $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";
  10. 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.
  11. 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) …
  12. 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.
  13. It looks fine to me (http://bit.ly/144fHH6); maybe Device Magic is sending something incorrectly?
×
×
  • 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.