Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. Well I tried the code myself and it worked just fine in IE8. Are you sure you have javascript turned on in your browser? Looking at the right file?
  2. but anyways, "body" and "document" is not the same as "#login" at all. You will have to post the context of where "#login" is.
  3. The only thing I can think of is that 'body' is part of the page but it's not ALL of the page, so you can't necessary click anywhere in your window and see the popup. Or else, it may or may not happen depending on what browser (version) you use. I mean for instance, with nothing else except for that snippet of code, I personally don't expect to be able to see that alert when clicking anywhere in the browser, because you don't actually have any html or body tag or anything. Even if the browser auto-generates those tags for you...why should the body tag span the entire window when you have nothing in it? I know it's an example, but for instance: $(document).ready(function(){ $(document).click(function(){ alert('a'); }); }); That works for me, even in IE8. Point being that even without any html or anything, everywhere in the browser window is somehow part of the document.
  4. okay so now I'm confused. is your .click() for #login or body? Or are you saying that you have that 2nd bit of code inside the first? Post your full code and also specifically which version(s) of IE it doesn't work in
  5. All by itself that should work in IE6-8. Can't speak for IE9 since that's kinda new and in beta...but I don't see why it shouldn't. Maybe it is something within there (that //code to execute here) that isn't working?
  6. You really should be using an xml or dom parser instead of regex for this sort of thing.
  7. .josh

    Help with Regex

    There is no graceful way to pass additional arguments to a function in a xxx_callback(). As of php 5.3 you can but even then the syntax readability is less than desirable. What I do is instead of passing data as arguments, I make it accessible within the function by declaring it as a global variable within the function and then pass it to a static variable (variable persists from function call to function call but stays within function scope) or non-static (variable lasts for duration of single function call) depending on my needs. Example: function someFunction ($matches) { // $matches[0] is the full current match // $matches[1] is whatever the value of your s param is // $matches[2] is whatever the value of your a param is // declare $someVar as a global variable so the function can access it global $someVar; // declare a static variable static $_someVar; // assign the global variable to the static variable and use the static variable if(!$_someVar) $_someVar = $someVar; // do whatever calculations, assumed resulting, final string you want to replace the pattern with is put into $replacement // use $_someVar as the variable you wanted to pass (don't touch $someVar) return $replacement; } // end someFunction $someVar = 123; // this is the variable you want to pass to someFunction $message = "hen an unknown printer took a galley of type and localhost/view.php?s=324&a=2433 scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic localhost/view.php?s=33&a=222 typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing"; $regexExpr = "~localhost/view.php\?s=([0-9]+)&a=([0-9]+)~" ; $message = preg_replace_callback($regexExpr, "someFunction", $message); The idea here is that you have a variable you want to pass to the callback function, but instead of passing it as an argument, you declare it within someFunction() as global so you can access it. But then you immediately assign it to a static variable and use the static variable instead (so that you aren't using/changing the global variable). Now I know some people might have a knee-jerk reaction to say using a global within a function is evil incarnate because it defeats the purpose of having scope, but IMO this is one of the few times where using globals within a function is acceptable. IMO this makes the code more readable. Also, I don't actually USE the global variable. I just declare it as a global variable and copy it to a static variable and use the static variable. Note: I ONLY do this for xxx_callback() type functions. I do not do this for calling other functions..
  8. You can use $_SERVER['argv'] to get arguments passed. Example: CLI: php.exe script.php filename.txt script.php print_r($_SERVER['argv']); output: Array ( [0] => script.php [1] => filename.txt )
  9. Only way to do it is as you have already suspected, make either a whitelist or a blacklist. Whitelist is easier to make and maintain, safer.
  10. echo '$firstname'; You need to either use double quotes "..." or no quotes. Variables are not evaluated in single quotes. date(‘Y-m-d H: -- i:s’) You can't use those funky quotes. PHP recognizes normal single or double quotes '...' or "..." Also in the future, try to be more descriptive of the problem. Explain what you expect to be happening and what it is not doing that you expect. Explain what it is doing instead. Just saying "It doesn't work" is not descriptive. Everything else is syntactically correct.
  11. The easiest way to do it would be to grab the jQuery library and use .show() and .hide()
  12. I'd PM an admin. As Maq said, it's against the rules, but you're new, have 4 posts as of right now, and it's reasonable to believe it was a typo.
  13. also for good measure you can throw .toString() into the mix to ensure it is a string:
  14. ...and this is the advantage of using document.write(). Using document.write() is NOT asynchronous. Browser will wait until the document.write() is finished executing, which includes waiting for the script tag to finish loading. Of course, if for whatever reason it doesn't load, you're fucked. With the appendChild method, yes, it is done asynchronously. Which is why I usually make use of setTimeout when going that route. Usually just timing it out by 250-500ms works just fine (kinda depends on how big your include script is and what all its doing...). However, another trick I do sometimes is to setup a recursive function call to keep checking for it and only execute when you get the green light. This is basically the same principle as the ready state change, though ready states can be somewhat tricky and not 100% guaranteed across all browsers. Basically it goes like this: B.js var x = true; A.js var obj = document.createElement("SCRIPT"); obj.type = "text/javascript"; obj.src = "B.js"; document.body.appendChild(obj); function creatNewEffect() { if (typeof(x) == 'undefined') { setTimeout('createNewEffect()',100); } else { this.effect = new JEffect(); } } createNewEffect(); That's just an example to show principle, I have no idea what the scope of this.effect is in your context, you will have to work that out.
  15. hmm okay... well looks like you worked it out before I could post but here was my alternative anyway.. preg_match_all('~\[(\d+)\]~',$data,$max); $max = max($max[1]); function renumber ($match) { global $max; static $ca = array(); $rep = (in_array($match[1],$ca)) ? "[".++$max."]" : "[".$match[1]."]"; $ca[] = $match[1]; return $rep; } $data = preg_replace_callback('~\[(\d+)\]~','renumber',$data); echo $data;
  16. seeing as how you seem to be willing/able to change any/all of them on the fly like that, why not just cut to the chase and rewrite all of them? $data = preg_replace_callback('~\[(\d+)\]~','renumber',$data); function renumber ($match) { static $c = 0; $rep = "[$c]"; $c++; return $rep; }
  17. okay scratch that above code, I got a bit ahead of myself and then timed out on editing post. This is correct code. Basically you first split at the delimiter you add and then parse each function $fs = preg_split('~/\*\* function[^/]+/~i',$data); array_shift($fs); foreach ($fs as $v) { preg_match("~function\s+(\w+)\s*\(([^\)]*)\)\s*\{(.*)\}~is",$v,$match); $functions[] = array('name' => trim($match[1]), 'args' => trim($match[2]), 'body' => trim($match[3])); } echo "<pre>";print_r($functions);echo "</pre>"; I know you can skip the preg_split and use preg_match_all instead of preg_match if you use a negative lookahead for the delimiter but I haven't quite wrapped my head around how to actually do that, so I opted to preg_split instead :/
  18. There is no way to gracefully handle nested {..} (or any nested delimiters for that matter) with regex, which is same reason why you shouldn't use regex to try and parse/traverse a DOM (you should instead use DOM for that). The easiest way to do this with multiple functions would be to place and look for a unique delimiter between functions, pretty much anything will work, but as an example: /** function x1 **/ function x1($p1,$p2) { echo 'test'; echo 'test'; } /** function x2 **/ function x2() { echo 'hi'; } You can then use that comment tag as a marker to know the boundaries of each function. Based on the above example, here is my take: preg_match_all("~function\s+(\w+)\s*\(([^\)]*)\)\s*\{([^}]*)\}\s*(?:/\*\* function[^/]+/|$)~is",$data,$matches); array_shift($matches); $n = count($matches[0]); for ($c = 0; $c < $n; $c++) { $functions[] = array('name' => trim($matches[0][$c]), 'args' => trim($matches[1][$c]), 'body' => trim($matches[2][$c])); } echo "<pre>";print_r($functions); echo "</pre>"; output: Array ( [0] => Array ( [name] => x1 [args] => $p1,$p2 [body] => echo 'test'; echo 'test'; ) [1] => Array ( [name] => x2 [args] => [body] => echo 'hi'; ) )
  19. well I guess if it's all the same to you and to your client, go for the one that makes you more money
  20. @TLG: Most likely the problem is that this line: this.effect = new JEffect(); // <-- Not defined is being executed before this line this.include('JEffect.js'); has a chance to finish loading. You probably want to wrap the line where you try to create the new object in a setTimeout or an onready or onload of some kind.
  21. well that doesn't seem to be what he's doing here...
  22. if all you are doing is exploding at the : and then checking each bit individually and ultimately throwing an error if either one fails to match, then you can skip the explode and individual checking and use the pattern/condition I supplied. The only adjustment would be to limit the numbers to up to 5 instead of just one or more, so: if (preg_match('~^[a-z]{1,2}[0-9]{1,5}:[a-z]{1,2}[0-9]{1,5}$~i',trim($_POST['startingCell']))) { // correct format, do whatever here } else { // not correct format, throw error or whatever } The only reason I can see for you to continue to explode and check each part individually, is if you were wanting to have a more specific error, like "starting cell is not right" vs. more generic "range as a whole is not right"
  23. can you provide more explanation about what the overall rules of the format is? From your post, it looks like you want 1 or 2 letters, followed by 1 or more numbers, followed by a colon, followed by 1 or 2 letters, followed by 1 or more numbers. Is that right? if (preg_match('~^[a-z]{1,2}[0-9]+:[a-z]{1,2}[0-9]+$~i',trim($_POST['startingCell']))) { // correct format } else { // not correct format }
  24. You have to do something like this: page where you are including script <script id='something' type='text/javascript' src='script.js'></script> inside your script alert(document.getElementById('something').src); Or retrieve the script src through other means (like get element by tag name or if you use jquery get it that way or w/e)...the point is that you have to get it by looking for the src of the script include.
×
×
  • 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.