-
Posts
1,832 -
Joined
-
Last visited
-
Days Won
3
Everything posted by salathe
-
preg_match() [function.preg-match]: No ending delimiter '^' found
salathe replied to bikeria's topic in Regex Help
[ot] I wouldn't go that far, to frown upon something simply because it does its job doesn't seem fair at all. Perhaps we should also be frowning on lazy quantifiers in equal measure? For the particular use in this thread (specifically, matching an email address with dot-at-dot style) then sure it might well be worthwhile to be lazy. Should be, "In some cases the regex engine doesn't..." There are equally times when using a lazy quantifier would be more work for the engine than otherwise. P.S. Ditto about the bookmarks, I might start using a phpfreaks tag on delicious for this purpose [/ot] -
[ot] It's not just function names that can be access with a "shortcut": other things that can be accessed are classes, "book" sections, control structures, etc.. More details are listed at http://php.net/urlhowto [/ot]
-
It actually doesn't, Mchl was right in saying "the value" <= "something else" evaluates to FALSE. If you swap them ("something else" <= "the value"), that evaluates to TRUE. I'm not sure how you arrived at the FALSE and NULL values.
-
The line is "parsed" from left to right as normal just in a different manner when it finds the curly braces compared to when none are present. It's not much to explain precisely how they're done differently, but perhaps that would just add cruft to the topic (do we really want to delve into opcodes here?). Not that this post in and of itself isn't fully crufty anyway! Sorry, don't mean to intrude. Carry on.
-
The differences in time spent using any of those methods will be negligible when compared to the time spent by your script talking to MySQL and likely other things happening in your script. Don't worry about which way of echoing a value is quicker until you really need it. Even then, do your own case-specific thorough research to arrive at a conclusion (if you can).
-
If you want help, there's no harm asking in the most relevant forum here: if people have the knowledge (or time/inclination to seek it out for you) then you'll get replies. If you don't get replies, there are plenty of AIR-centric communities elsewhere to ask for help. I've no idea how many PHPFreaks have played with AIR in whatever form. As would giving away kittens.
-
Why on earth would you need to know what a user's password is now, let alone all of their previous ones?
-
Use a newer version of PHP (5.3.0 or above) or move it out of the parameter: function sign() { return ($a = func_get_args()) ? vsprintf(str_repeat("<span>%s</span>", count($args = array_filter($a, "strlen"))), $args) : ""; }
-
It wouldn't take much to cook up (or find) a function to do this; you can then define the values which are acceptable in the resultant string (numbers, upper and/or lower-case letters, other symbols, etc.). For something like this the rand and mt_rand functions are "random enough".
-
Sure it can function sign() { return vsprintf(str_repeat("<span>%s</span>", count($args = array_filter(func_get_args(), "strlen"))), $args); }
-
I'm not exactly clear precisely what you are trying to achieve (perhaps I haven't read the thread carefully enough) so apologies in advance is this isn't helpful to you. However, the code below takes your array of objects (from SOAP or a hard-coded array for testing) and parses them into a neat array structure. I wasn't going to reply to the thread (not being clear if this is what you want) but the snippet below introduces a different approach to moulding an array of items into some other structure which even if it's not particularly useful to you darkgr33n, may be an idea for others to store for later consideration when doing a task like this. So, onto the snippet which produces the following structure/output from your array of objects (see $foo in above posts). Expected output array(4) { ["Street"]=> string(12) "Stanley Road" ["Town"]=> string(10) "Manchester" ["Number of Rules"]=> string(1) "2" ["Rules"]=> array(2) { ["X014"]=> string(18) "Rule text for X014" ["X015"]=> string(18) "Rule text for X015" } } The snippet function parse_foo($result, $value) { // Stores the last rule id (so its text can be related to it) static $last; if ($value->Label == 'Rule') { // Add empty rule (its value will come next) $last = $value->Line; $result['Rules'][$last] = ""; } elseif ($value->Label == 'Rule Text') { // Add value to rule $result['Rules'][$last] = $value->Line; } else { // Not a rule id or text $result[$value->Label] = $value->Line; } return $result; } // Lets see what parse_foo does var_dump(array_reduce($foo, 'parse_foo'));
-
That sounds like a good start, given the information presented.
-
How to Stop whole script or Jump to function such as GoTo
salathe replied to fbemo's topic in Javascript Help
Maybe I'm missing something obvious but couldn't you just return at that point? -
The link that I gave you earlier should cover the basics: http://dev.mysql.com/doc/refman/5.4/en/join.html
-
You'll be wanting a LEFT JOIN.
-
There are tonnes of ways of doing something like this, the following is just one example. preg_replace('#^<tr>(?=.*?<td>Hello</td>)#m', '<tr class="bgRed">', $html);
-
Use a JOIN in your SQL statement to pull back the access information for each user.
-
If you put these "problem" values into the database and pull them out again, is there still an issue with "\r"s?
-
In simple terms you can extend the character class ([…]) with the extra characters that you want to allow, for example [^0-9a-zA-Z.#, -]+ If you need stricter checking (the above would allow #.......,,,----### as a valid address) do let us know more precisely what you're willing to allow/deny.
-
It is "finding" true/false. The if expects a condition that evaluates to either true or false. In this case the condition is simply the value of defaults.nospace. So, if that is false then what is inside the if block will not be executed (i.e., spaces will not be removed from val). If it is true then the spaces in val will be removed. If you wanted to be super-specific, you could change the if line to read if (defaults.nospace == true) but that wouldn't change behaviour for true/false values. [ot] Since you're not superbly versed with JavaScript, I don't know whether you know about the shorthand form of writing regular expressions in JS. Instead of using new RegExp, you can use the form /regex/modifiers where regex is your regular expression ([ ]+) and modifiers are your pattern modifiers (g). To put this into context, your own code could be written in the two following ways: if (defaults.nospace) { var pattern = /[ ]+/g; val = val.replace(pattern, ''); } if (defaults.nospace) { val = val.replace(/[ ]+/g, ''); } Also note that since your character class ([…]) only contains one value (the space) it is not strictly necessary. The regexp might as well be / +/g which would work in exactly the same manner. [/ot]
-
Can you not just do that, but with PHP syntax? if ($var == 'abcdefg') { echo 'bob'; } if ($var == 'hijkl') { echo 'jim'; }
-
Fair enough, that explains it.
-
[ot]Forgive me for intruding but is there any reason you're using that particular format for the text file? It strikes me that using something like JSON[1], YAML[2], INI[3], etc. would make life simpler than manually parsing the file with regular expressions. Currently, the file bears a passing resemblance to JSON. [*]http://json.org/ http://php.net/json [*]http://yaml.org/ [*]http://en.wikipedia.org/wiki/INI_file http://php.net/parse_ini_file [/ot]
-
failed to open stream: No such file or directory
salathe replied to travelkind's topic in PHP Coding Help
Does the folder /html/beer/uploads/ exist and does the web server have write permissions to it? Do you not, instead, want to be saving the file to the /home/content/d/l/a/dlanden/html/beer/uploads/ folder? Try move_uploaded_file($_FILES['img1']['tmp_name'], dirname(__FILE__).'/uploads/'.$_FILES['img1']['name']) Edit: or what mrMarcus said.