Jump to content

mkosmosports

Members
  • Posts

    196
  • Joined

  • Last visited

    Never

Everything posted by mkosmosports

  1. Thanks for your suggestion smc, Im still convinced on using regex here though. thefortress, thats a very nice tutorial you gave the link to. Ive been able to form the following condition, but it always returns true, no matter what I enter into the field! if (!preg_match("[a-zA-Z0-9_-]{4,20}",$field)) { $_SESSION['error'] = "$field value must be between 4 and 20 characters. Please start again."; header('Location: reg_signin.html'); exit(); } Once again, I want the above to filter out any $field values that have characters other than alphanumerical ones, hyphens or underscores and are shorter than 4 or longer than 20. How come its not working? Any suggestions for the new regex beginner? Thanks.
  2. True...that would work. I was hoping to do it using regular expressions though as it would be much shorter....
  3. Hey, Im in the midst of creating a secure signin script which brings me to two questions I have. 1. I want to filter out blank spaces from the login and password fields. Im very unfamiliar with regular expressions, so I went out and found the below script on the web: function no_specialchars($field1) { if (!eregi("[a-zA-Z0-9]+",$field1)) { $_SESSION['error'] = "The password or username fields should only contain alphanumerical characters or hyphens and underscores."; header('Location: reg_signin.html'); exit(); } } This function seems to do the trick when I try to signin with most special characters (although not all of them?!) and only spaces, however it still lets me pass when I put spaces before, in between or after the text string. What I want is to filter out any spaces and any special characters except for hyphens and underscores. Any ideas? Thanks in advance. 2. My second question would bring me to the handling of an error caught by the filter. Im using sessions where the session key 'error' is created once the filter finds a problem. This session data is then kept and displayed at the original signin form page. Is this the ideal way to do it or should I maybe put url variables to the redirect link such as header('Location: reg_signin.html?error=1'); and then read the user the error according to the error GET value? Thanks everyone...
  4. Beautiful! This works great chigley. Now I just gotta break it down and understand it better.... I appreciate your help and time!
  5. Hey, Ive got a file which contains around 150 lines of the following html: <option value="56">Team Canada</option> What I need is to transform each of these lines to be: <div class="teamlist"><a href="team.php?team=56" target="_blank">Team Canada</a></div> Im thinking the easiest way to accomplish this is to get "Team Canada" and "56" into an array, where "56" would be the associative key to "Team Canada". Any ideas how I could accomplish this? Thanks!
  6. Thanks boo lolly. That works. Ive created another method though that doesnt require creating arrays (I need strings in the end anyways). Here it is using the below string: $string1 = '100-500'; $lowval = substr("$string1",0,strpos("$string1","-")); //Number before - $highval = substr(strstr("$string1","-"),1); //Number after -
  7. Hey, Ive got the below strings: 100-500 3450-7890 Is there a function I can use to extract the strings before and after the "-"? Thanks!
  8. Hey dsaba, Unfortunately I dont know that value beforehand. I do have that number in a database, so I can take it out from there anytime, however, my script creates this file in its beginning stages, and since the file already contains the information Im looking for, Im hoping theres a way to reuse it....
  9. Hello, Ive got a file which contains the following data: <option value="13">African Nations Cup XXV</option> <option value="16">asd</option> <option value="7">Champions League</option> <option value="1">English Premiership</option> What Id like to do is get the maximum value, so 16. Ive used file_get_contents to bring the file into a string, but now Im stuck getting that max value out. Unless theres a function for this, I believe the direction I would need to take is collect all value numbers using some string manipulation function, throw them all into an array, and just get the max value of the array. Is there an easier way? If someone could point me in the right direction I would appreciate it... Thanks!
  10. Hmm...good question. By 'effective' I mean most logical, fastest. (maybe 'efficient' is the better word here) Not necessarily trying to make sure its easy code and it does seem like updating all fields regardless of changes is doing unnecessary work. Id also like to improve my php knowledge, so Id rather write the appropriate script regardless of its difficulty. Unless you think updating all fields in this case would be the preferred option after weighing out the overall pros and cons... Thanks
  11. Hey, Im thinking of the most effective way I could do an update of already exisiting mysql data through forms. So far, Im thinking my choices are: 1. Simply update all mysql fields regardless of if theyve changed or not. 2. Run some kind of a match (maybe preg_match) between the new form entry and the existing mysql entry. (Im not too familiar with this one) 3. Hoping someone from this forum can give me a push into the right direction... Thanks! mkosmosports
  12. Nevermind frost. I got it figured out. The definition of the $write variable needed to happen within the foreach....
  13. Man, I just cant seem to finish this off. Using the code below Im attempting to run the query results of 4 different queries into four separate files.... $allgroups = @mysql_query("SELECT id, name from sf_group ORDER BY name"); $allteams = @mysql_query("SELECT id, quick_name from sf_team WHERE linkable = 'y' ORDER BY quick_name"); $allplayers = @mysql_query("SELECT id, nick_name from sf_player ORDER BY nick_name"); $allarticles = @mysql_query("SELECT id, title from sf_articles"); $type_arr = array("allgroups" => array("groups","name"),"allteams" => array("teams","quick_name"),"allplayers" => array("players","nick_name"),"allarticles" => array("articles","title")); $write = ""; foreach($type_arr as $key => $value) { while($row = mysql_fetch_array($$key,MYSQL_ASSOC)) { $write .= '<option value="'. $row["id"] . '">'.$row["$value[1]"]."</option>\n"; } $file = fopen("$value[0]"."_"."select.html", 'w+') or DIE("Could not open file to write to"); fwrite($file, $write); fclose($file); } The problem Im having now is that the files that are being written contain more than theyre supposed to. I want them each to contain only the contents from the query currently being looped through but what happens is the first file is correct but the second one contains the query results of the first plus its results, and so on after that.... I want it to only write the contents of the query its currently looping through... Any ideas? Thanks!
  14. Damn, looks like Ive got one last question for you. Im trying to insert a line break (\n) after every line thats inserted into this new file but its always printing it out as opposed to applying the line break.. $write .= '<option="'. $key . '">'.$val.'</option>'"\n"'; Thanks
  15. Thats a pretty nice shortcut. Thanks frost.
  16. Works beautifully! I appreciate the help frost. Can you explain to me what the .= means when you define the $write variable? Thanks!
  17. Hey, Thanks for your help on this one frost... Im getting an error related to the write variable... Notice: Undefined variable: write in C:\Web\Apache2\htdocs\index.html on line 122 Warning: fopen(writeto.txt) [function.fopen]: failed to open stream: No error in C:\Web\Apache2\htdocs\index.html on line 127 Warning: fwrite(): supplied argument is not a valid stream resource in C:\Web\Apache2\htdocs\index.html on line 128 Warning: fclose(): supplied argument is not a valid stream resource in C:\Web\Apache2\htdocs\index.html on line 129
  18. Hey, Ive got the below array: [geninfo] => Array ( [groups] => Array ( [13] => African Nations Cup XXV [7] => Champions League [1] => English Premiership ) ) And Id like to write its contents to a file, but that content needs to be written in a certain format. Id like that format to be <option value="(array key)">(array value)</option>... Ive tried some variations using the file_put_contents and implode functions but I havent been able to arrive to what I want to do... Can someone help out? Thanks for any ideas! mkosmosports
  19. Beautiful, much quicker than other options I had considered like trim or preg_replace..... Thanks!
  20. Hey, I have the following string: $test = "12/12/2007" What would be the most effective way of removing the forward slashes to come up with a "12122007" result? Thanks!
  21. Hey, Ive actually figured out another way to do this which looks less complicated then the one php.net suggests. So ive got my array: Array ( [4] => Array ( [fullname] => Marek Kosmider [title] => Arsenal: Why do they lose so often? [adate] => 2007-03-11 [acontent] => articles/20070311_Kosmider_Arsenal_why.html ) [3] => Array ( [fullname] => Marek Kosmider [title] => Chelsea: Complete sheit! [adate] => 2007-03-11 [acontent] => articles/20070311_Kosmider_Chelsea.html ) [2] => Array ( [fullname] => Orlando Monchez [title] => Carlos Tevez: Not the West Ham saviour after all [adate] => 2007-01-07 [acontent] => articles/20070107_Monchez_Tevez.html ) ) Then I run a loop to pull out the ids, place them into another array and that way I can easily get the max.. foreach($artarr as $key => $value) { $ids[] = $key; } So, $ids[0] would be the max.
  22. But in my case its a multidimensional array, so using $max = max($my_array) results in Array...
  23. Hey, No, Im actually looking for the maximum numeric key, which would be 4....
  24. Hey, Ive got this array Array ( [4] => Array ( [fullname] => Marek Kosmider [title] => Arsenal: Why do they lose so often? [adate] => 2007-03-11 [acontent] => articles/20070311_Kosmider_Arsenal_why.html ) [3] => Array ( [fullname] => Marek Kosmider [title] => Chelsea: Complete sheit! [adate] => 2007-03-11 [acontent] => articles/20070311_Kosmider_Chelsea.html ) [2] => Array ( [fullname] => Orlando Monchez [title] => Carlos Tevez: Not the West Ham saviour after all [adate] => 2007-01-07 [acontent] => articles/20070107_Monchez_Tevez.html ) ) How can I pull out the max 2nd level array key which would be 4 in this case? Thanks.
×
×
  • 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.