-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by salathe
-
Urgh, why make it in entirely the wrong forum? I guess it slipped under my radar (was on vacation ) and I would never have thought to look in there for an announcement!
-
Before offering up a hand with the decimals, are you aware that your current regular expression only makes sure that the price has a single digit or whitespace character (space, tab, etc.) but can contain any other characters as well? For example "this is not a number" will be accepted! Can you see why? Have you had a stab at allowing decimals yourself? Either way, take a moment to browse around a reference site [1] and try to familiarize yourself with the regex approach to problem solving (not everyone gets it). Have a stab at it yourself; folks here much prefer teaching people to fish (or, code) over giving others a free meal (though, if you're lucky!). [1] E.g. http://www.regular-expressions.info
-
Is there such a thing as overdoing it?
salathe replied to crmamx's topic in PHPFreaks.com Website Feedback
*salathe puts forward a motion to promote cssfreakie just to see what happens -
It would have been nice to announce this sort of thing; mostly to show that the place is being looked after, but also to celebrate the awesome new features available (are there any?). P.S. Apologies for wandering off topic!
-
The closest that you'll be able to get (simply) with DOM would be to get the textContent of the appropriate <script> element. That'll be a good start at least.
-
Ooh, I totally missed that the button has gone walkabout.
-
Now that I know you've read the manual () I'll copy the answer into here for any future visitors having the same issue (if you do, go read the manual page!). P.S. Don't forget to mark the thread as "solved"
-
It looks like you want to parse a piece of (broken) JavaScript text within the HTML. You could use DOM to get get at the block of JavaScript code, then use string functions go narrow it down to the particular piece of code you are interested in. Optionally you could then use something like json_decode() to parse that (broken) JSON (the {...} part) into PHP values, or keep going with the string functions.
-
See example #3 on http://php.net/simplexml.examples-basic
-
Of course, the staff here might like to open up a more "social coding" type of forum; especially since the freelance forum is closed for replies.
-
It's still work, paid or otherwise.
-
What is your budget? How meaty would you like your server? One, many, a couple? What work is the server(s) expected to perform?
-
Isn't this what the freelance forum is for?
-
Thanks.
-
Converting part of DOM / XML document to a String
salathe replied to UltimateWeapon's topic in PHP Coding Help
By the way, my snippet could be simplified since you only want a string (I usually want to play around with the DOMDocumentFragment some more). $myString = ''; if ($cars->length > 0) { foreach ($cars->item(0)->childNodes as $child) { $myString .= $newdoc->saveXML($child); } } -
Converting part of DOM / XML document to a String
salathe replied to UltimateWeapon's topic in PHP Coding Help
Welcome to PHPFreaks, UltimateWeapon. This seems like an odd request, and an even odder example file to work with, but I'll humour you. Here's a snippet which, using DOM as you wanted, takes the source XML and, via a DOMDocumentFragment (which many people have never even heard of, so don't worry if you haven't), outputs the content of that <cars> element. The important stuff is overly-commented within the if() block. $xml = ' <everything> <cars> <car>ladia</car> <car>ferrari</car> <garage>big blue building</garage> i also have a McLaren F1 but i wont brag about it </cars> <houses> <house>Big Red House</house> </houses> </everything> '; $newdoc = new DOMDocument(); $newdoc->loadXML($xml); $cars = $newdoc->getElementsByTagName('cars'); $myString = ''; if ($cars->length > 0) { // Get the first cars element $cars = $cars->item(0); // Create a new, empty DOMDocumentFragment $fragment = $newdoc->createDocumentFragment(); // Loop over cars childNodes and add a copy to the fragment foreach ($cars->childNodes as $child) { $fragment->appendChild($child->cloneNode(true)); } // Save fragment as an XML string $myString = $newdoc->saveXML($fragment); } var_dump($myString); To read: DOMDocumentFragment DOMNode::cloneNode() DOMDocument::saveXML() -
How can I set php dates 10 years into the future?
salathe replied to liquid2g's topic in PHP Coding Help
If you hooked a little plugin into your Wordpress which alters what the_time() outputs, you would not have to change any of your theme files. I know that you said you're new to that, but it would be way easier than what it looks like you're currently trying to do! -
Weird. Are any of you keeping track of the cookies and what not being sent on the occasions when you get logged out? Not very helpful, but I've been logged in for longer than I can remember on 4 different machines (and 6 browsers) without any problems.
-
In case you haven't read already, there is a nice section in the PHP manual on using regular expressions. Relevant to the code posted above is the section on delimiters.
-
The error should give you a hint. If not, post it here and we can guide you. (The problem is very clear already, but handing folks answers isn't really helping at all!)
-
Good work pikapika!
-
How can I set php dates 10 years into the future?
salathe replied to liquid2g's topic in PHP Coding Help
Another approach would be to ignore all of the helpful comments here and attach a filter (using Wordpress's add_filter() in a plugin) to the_time to do any manipulation of the date/time that you want to do (including, adding 10 years). -
Can this PHP code be valid: $4bears = $bears->getFirst4();
salathe replied to ansharma's topic in PHP Coding Help
It's a valid variable name, in the sense that a variable can exist called "4xyz". However, it is not a valid label (the part that comes after $ to denote a variable). In other words, you cannot define a variable name like $4xyz but you can define it using the $GLOBALS superglobal variable ($GLOBALS['4xyz']) or a variable-variable ${'4xyz'}. But... don't. Mostly because it will generate a parse error. -
The only thing that you likely need to change from the code in the first post are the two occurrences of /downloads/. Unless of course your files live in /downloads/*.zip (an absolute path from the root of your server, not the web root, not relative to the the PHP script!) and in /path/to/web/root/downloads/*.zip. So, the first /downloads/ should be the path to the files on the server filesystem either absolute (E.g. /home/myserver/downloads/) or relative to the script (E.g. ./downloads/). Then the second /downloads/ should be the web path of the files (which might be /downloads/). There's absolutely no need for your script to use cURL or file_get_contents() on the files.