-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by salathe
-
email address is domain account user name @ the server name
salathe replied to Chrisj's topic in PHP Coding Help
This is for PHPMailer 6. This is for PHPMailer 5. Which version do you actually have? -
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. ?
-
PDO. How to pass quote literal as part of query?
salathe replied to nik_jain's topic in PHP Coding Help
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. -
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()
-
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).
-
Is this normal or should I be concern?
salathe replied to Sam46's topic in PHPFreaks.com Website Feedback
I've been here for 4 years and have a little over half as many profile views. I guess you're Mr Popular. -
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.
-
"6/8/2013 1:02:37 AM" converted to unix timestamp
salathe replied to gamefreak13's topic in PHP Coding Help
Why would you feel safer? strtotime() has a finite list of formats that it will accept, yours is one of them. -
No, it won't.
-
$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";
-
Whaaaa?
-
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.
-
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) …
-
strtotime() is interpreted differently on different servers
salathe replied to MockY's topic in PHP Coding Help
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. -
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.
-
How large a range of numbers are you looking for, are 2147483648 numbers not enough?
-
I don't know what you're talking about, the forum has been fine the last few days.
-
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.
-
Start here: http://php.net/manual/en/reference.pcre.pattern.posix.php
-
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.
-
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");
-
SoapServer - how to add namespace to response
salathe replied to immortallch's topic in PHP Coding Help
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? -
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));
-
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.