-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by salathe
-
With that regex, >= will never get matched because > and = both occur individually before it in the group of alternatives. Matching stops at the earliest successful match of an alternative. If you moved >= earlier (at least, before = and >), then it would work fine just like <= does.
-
Thanks for providing the XML. It looks like the only problem is that the <receiveddata> elements contain (many) [/tt] which makes it not valid XML. What you do from here is entirely up to you, but if possible ask the XML provider to fix their XML. A simple [tt]str_replace() on the XML, to remove those invalid character references, is enough to make SimpleXML happily load the XML.
-
Can you give a link to the XML on the "other server" (or an exact copy of it somewhere else)? What do you mean by "remove html" when you save it locally?
-
parsing a larger number of locally based files...
salathe replied to dilbertone's topic in Regex Help
Hi there. You didn't ask anything in the last post, are you happy with the code that you've got or do you still have questions or things that you would like to talk through? -
The XML contains an invalid character reference (x0;), which is not allowed in XML 1.0. Wherever you're getting the $xml string from needs to be fixed in one way or other (using CDATA perhaps if you need the NUL characters, or just by not including the illegal character referencess).
-
Great (and thanks for taking the time to figure it out!). Just be aware that, because the regex is not anchored (see my previous post), it will match against strings containing anything on either side of what your pattern is matching. If you want to make sure that a string contains only the lat/lon number, then you must anchor the pattern. For example: $subject = 'test 123.456789 string'; $pattern = '/[0-9]{1,3}\.[0-9]{6}/'; if (preg_match($pattern, $subject)) { echo "Unanchored pattern matched against '$subject'\n"; } $pattern = '/^[0-9]{1,3}\.[0-9]{6}$/'; if (preg_match($pattern, $subject)) { echo "Anchored pattern matched against '$subject'\n"; } Finally, this may or may not be a problem but, your regex will allow numbers like 001.234567.
-
Easy... reading the documentation for pathinfo() shows you how. $path = "/my/file/path/US_*.xls"; $info = pathinfo($path); $path = $info['dirname']; $ext = $info['extension']; How exactly do you want to utilize the path/extension in $handle? Using only a path and/or extension doesn't make much sense for opening a file. Are you trying to do what AbraCadaver guessed at: get a listing of all .xls files in a directory?
-
To elaborate a little more on what requinix said, this page has a little more detail (though it can get quite eye-glazingly technical) — http://php.net/regexp.reference.subpatterns
-
Have a read through http://php.net/regexp.reference.repetition as that seems to be where you're having most trouble. After that, be sure to (re-)familiarise yourself with http://php.net/regexp.reference.anchors Post back if you a) find a solution (sharing is caring) or b) still have trouble.
-
Which "many solutions" have you tried so far?
-
This question is mostly about how to loop over an array and produce a HTML table so rather than give you an answer specific to your object, let's try and make you think a little. Suppose we had the following array, how would you a) loop over it, and b) output a table? $array = array( array('a' => 'apple', 'b' => 'banana', 'c' => 'cherry'), array('a' => 'aardvark', 'b' => 'badger', 'c' => 'cat'), );
-
Not really besides, "don't think too much about it." The LogicException is fine (and would be the one that I would choose), unless you have any particular need or convention to have one specific to your framework.
-
Simple print_f() example from the php.net site won't display right.
salathe replied to Slips's topic in PHP Coding Help
Yes, it is entirely normal and you will see the same behaviour in all browsers. There are technical reasons why, in HTML, the format of the document (how the HTML source code looks) is different from how it is rendered (how it looks in a browser). But all that you need to know is that multiple spaces are displayed as just one (unless you use something like <pre>) so the following all display in the same way (as Some text here). Some text here Some text here Some text here -
A LogicException would be fine, as it (trying to write to a read-only property) would be a logic error.
-
You've marked this as solved... is it?
-
Simple print_f() example from the php.net site won't display right.
salathe replied to Slips's topic in PHP Coding Help
Are you viewing this in a web browser (likely, unknowingly, as HTML)? The padding is happening but you just can't see it. Do one of the following: Use "view source" in the browser to see what is really being output. Send the text as plain text, using ini_set('default_mimetype', 'text/plain') or similar, instead of HTML. Preserve the spacing, even in HTML, by wrapping the output in <pre> tags. -
Which exception(s), if any, have you been considering? If you did make your own, what would it be?
-
Check whether something is iterable using foreach?
salathe replied to phant0m's topic in PHP Coding Help
Yep. -
It's true though. Come on folks, quit giving shitty non correct answers wtf (In all seriousness, thanks to all who do give their time and experience in the pursuit of helping others here.)
-
Those values are not attributes in the usual sense. Attributes are part of an element's opening tag and look like blah="value" in the XML. With SimpleXML, they would be visible when using print_r as items within an @attributes property, but none of this is useful to you. The main problem is that your element name (advertiser-id) is not a valid object property label in PHP so, as you've seen, you cannot access it like $o->advertiser-id since PHP interprets that as an arithmetic operation $o->advertiser minus id. To access properties containing invalid characters you have to use a special syntax (this is not particular to SimpleXML, the same goes for any object) like $o->{'advertiser-id'}. An example of this is given in the PHP manual's "Basic usage" of SimpleXML... see Example #3 on http://php.net/simplexml.examples-basic Edit - Ahh, too slow. Well, you've gotten the answer twice now.
-
parsing a larger number of locally based files...
salathe replied to dilbertone's topic in Regex Help
How large is large? How do you think you would parse the stuff? There are many ways to "parse" a document; for HTML you could use the DOM to get an object-based view of the file, or you could read in the whole file and do a quicky preg_match_all(), or if it's really huge you could read it line-by-line and test each line for matching links. -
Hover-over ads for dog food? Really?
salathe replied to ManiacDan's topic in PHPFreaks.com Website Feedback
Ouch. (I'm so glad that I've not experienced any of these advertising changes/tests!) -
There are differences between PHP versions, "first day" will do as you describe for versions 5.3.0 through 5.3.2 inclusive, but not earlier or later versions (or future). The formats that strtotime and the DateTime class accept are documented here: http://php.net/datetime.formats. What formats are available when could be clarified but you get the idea.
-
strtotime() is not magic, it only understand specific input. Your "first day" is simply (quite rightly) being interpreted as a movement relative to the specified timestamp, basically "add one day". To get the first of the month, you must use "first day of" which was added to the date string parsing in PHP 5.3.0. Without that being available to you, an alternative is to use mktime() or as jdavidbakr pointed out, just fake it.