Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. The script for those are fairly easy to write, especially the cookie one, the problem I was pointing out though is that they aren't very reliable.
  2. That error means you are using a function that is being removed from the core. the posix compatible regular expression functions are being removed by php6, so you should switch to the pcre regex function equivalent: if(strlen($key)<>32||preg_match("~[^a-f0-9]~",$key))
  3. without forcing the user to register there is little you can do to prevent it. You can: - set a cookie and look for it, hope the user doesn't delete it - grab and store IP address and compare it with request, hope the user doesn't go through a proxy or there aren't multiple users on the same network with a login system: - real easy to enforce it on the account, but you are basically back to the above as far as users signing up with multiple accounts
  4. Have you bothered to try and sort it out yourself? If you take the time to actually read the error messages, they help you figure out what's wrong, and it's fairly self-explanatory..."Undefined Index" means you are attempting to call an array element that doesn't exist. "Missing Argument" means you are not passing enough arguments to a function call. "Undefined Variable" attempting to use a variable that doesn't exist. Pretty self explanatory...and it tells you what line number and everything. Those are easy errors to fix, there's no reason you can't figure them out yourself.
  5. so tell it to show you the image instead.
  6. regex not necessary $file = file('test.txt'); $c = 0; foreach ($file as $row) { $row = explode(':',trim($row)); $list[floor($c)][$row[0]] = $row[1]; $c += .5; } echo "<pre>"; print_r($list); [pre] Array ( [0] => Array ( [sTART_TYPE] => DISABLED [DISPLAY_NAME] => Alerter ) [1] => Array ( [sTART_TYPE] => AUTO_START [DISPLAY_NAME] => AutomaticUpdates ) [2] => Array ( [sTART_TYPE] => DEMAND_START [DISPLAY_NAME] => BackgroundIntelligentTransferService ) [3] => Array ( [sTART_TYPE] => DISABLED [DISPLAY_NAME] => ClipBook ) ) [/pre]
  7. no, that did not work perfectly. All that condition does is check if $valid exists. It does not compare the variable to what's in the array. As far as the condition is concerned, it's just an arbitrary string. your condition is basically the same as if (isset($valid)) If you think that it is doing what you think it is doing, then try this: $clanID = 5; $dm = array('clan1'=>1,'clan2'=>2,'clan3'=>3); $valid = ''.$clanID.'=='.$dm['clan1'].' ||'; if($valid) { echo $clanID . " is in array! wait...."; } If you want to check if a value is in an array, this is what you would do (example): $array = array(1,2,3,4,5); $value = 3; if (in_array($value,$array)) { // the value of $value is in the array $array } else { // it is not
  8. umm... I don't think that's doing what you think it is doing...all you are doing is setting a regular string value to $valid, and the if() condition just checks if $valid exists, which it does. It's not actually comparing $clanID to $dm['clan1']
  9. $_SERVER['HTTP_USER_AGENT'] will have browser info from the header request. You will need to parse the info out, though get_browser may be useful for you for that. Make some conditions using if or switch and redirect with header (don't forget to exit after the header call to stop the rest of the script from executing).
  10. yes you can create an array like that, with a comma after the last value. What is actually happening is you are assigning a null value to the element after that last value, which basically negates itself. However, I have no idea what you are actually trying to accomplish in your code specifically...
  11. function create_link($matches) { // link_id should be an auto-increment field $insert = mysql_query(sprintf("INSERT INTO links ( link_url ) VALUES ( '%s' )", $matches[1])); return '<a' . $matches[1].'href="' . mysql_insert_id() .'"' . $matches[3] . '>' . $matches[4] .'</a>'; } // File name, could be a url $file = 'file.html'; if (file_exists($file)) { $content = file_get_contents($file); // Regex replace string $pattern = '/<a([^>]*)href="([^"]+)"([^>]*)>([^<]+)<\/a>/s'; $content = preg_replace_callback($pattern, 'create_link', $content); echo $content; }
  12. first thing i notice is looks like you aren't checking for negative numbers.
  13. $batch_contents = preg_replace('~(\$batch_file1 = ")[^"]*~i', '${1}'.$newArgument,$batch_contents);
  14. You have to assign the function call to a variable so that the returned $newarray gets passed back: $array = split_to_array($string); Then $array will have the value of $newarray value. Alternatively, you can do like global $newarray; at the beginning, inside your function. This will make $newarray globally scoped. Then you won't have to return anything. However, I do not recommend doing this. Go for the first suggestion: assign the returned value to a variable. p.s.- as nightslyr mentioned, explode() is better. It is optimized for splitting strings by another static string. You should only use preg_split if you are trying to split by a non-static pattern.
  15. okay well the font seems to look the same in both of those screenshots and in your code you don't specify a path/to/font at all so I assume that your fonts are in the same dir as your script and the font itself is shiny. Your computer has GD2 so fontsize is measured in Points (pt). Your server has GD1 so fontsize is measured in pixels (px). 8pt == 10px so you need to change $fontsize = 8; to $fontsize = 10;
  16. post your code
  17. honestly I'd setup and use something like SQLite if having a full database isn't an option... But anyways, I understand your desire for secrecy, but there's no way we can even begin to judge how much your product is worth when you don't show it. If you can't show us a demo of it, how exactly do you plan on pitching a sale to your potential clients?
  18. .josh

    Regex help

    Can't really give you a suggestion about how to get your list of files into the $files array below unless you provide more details....but this should do the trick (I suggest you make backups first): $files = array('file1.html','file2.html','file3.html'); foreach($files as $file) { $file = file_get_contents($file); $file = preg_replace('^.*?</head>(.*?)</html>(.*)$~is','$1$2',$file); file_put_contents($file); } You might (probably will) also need to use set_time_limit or something to keep your script from timing out.
  19. findstr /R /C:"Maximumpasswordage(days):[0-90]" final.doc (Maximumpasswordage\(days\):\[)([^\]]+) The part of the string not matched in preg_replace Capture what is matched Match some literal text to isolate what you are wanting to replace. couple of backslashes thrown in there to match literally because parenthesis and square brackets are special characters in regex Negative character class: match 1 or more character that is not a closing square bracket. This matches your x-y between the opening and closing brackets. '${1}'.$newArgument $1 a temporary variable containing the first captured group of the pattern (the red stuff above). This is captured because a preg_replace replaces everything matched in the pattern. So you need to capture the stuff you are matching but not actually replacing, so that you can put it into the replacement so you don't lose it. The {} wrapped around the 1 is to prevent ambiguity. if $newArgument is "5-60", what happens normally is preg_replace tries to parse "$15-60" so it tries to use $15 (which doesn't exist) instead of $1. So the {} is used to tell preg_replace that you want $1 not $15.
  20. $newArgument="5-60"; $batch_contents = preg_replace('~(Maximumpasswordage\(days\):\[)([^\]]+)~','${1}'.$newArgument,$batch_contents);
  21. Ah okay, I slightly misunderstood, I thought it was the other way around, checking if 'US' was in array. I like the array_unique solution. Here's another one-liner: if (count(array_diff($countries,array('US'))) > 0) { // non-US in array }
  22. in your OP your query for the teams table is being put in $z but you are echoing out $row
  23. I still think it's a problem with the font. Since you still haven't posted any code, I'm still just guessing here...I'm guessing you are using imagettfbbox and/or imagettftext? Are you using the same version of the GD library on your localhost as your server? If it is a different GD version you may need to adjust the path/to/fontfile and/or how you specify the font size (unit-wise).
  24. uh yeah...you seem to be completely missing the point of a function... functions are for when you have some code being used over and over in places and instead of having the code over and over again you wrap it up and slap a label on it and call it. Anyways, supposing for whatever reason you want to continue down this futile path...you can't dynamically create functions like that. Look into prototyping or eval()
×
×
  • 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.