Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Something like this: <?php $array = array(1,2,3,3,4,5,5); $unique = array_unique($array); $duplicates = array_diff_assoc($array,$unique); print_r($duplicates); ?>
  2. Anyone else noticed the lack of top border on your own post, but only when your post is the last one in the thread(and possibly the page)?
  3. If you want to answer the question of whether or not you can program something with artificial intelligence, you'll first need to define intelligence. People have been arguing about that for years, so dont expect to find an answer any time soon. If you google for Searle's Chinese Room (it's a thought experiment) you'll find a load of stuff relating to this. Personally, im with Searle - hard AI doesn't seem like intelligence at all.
  4. Well, i'd read the lines into an array, set a variable to zero, increment that variable inside a foreach loop and only echo when it's divisible by two: $file = file('path/to/file.txt'); $i = 0; foreach($file as $line){ if($i % 2 == 0){ echo $line.'<br />'; } $i++; }
  5. Is the online play still shoddy on ps3? Absolutely terrible when i tried it a while back on my ps2.
  6. If you're looking for someone to do this for you, you should be posting over in the freelance board
  7. Dont. Use mysql_real_escape_string However, you might want to consider what you're allowing through - unless this is something hidden away in an admin area, someone could use things like script tags and you'll end up in a whole heap of trouble.
  8. What do you mean by 'send sessions'? If you are trying to stay logged in across requests or something similar, you should be ok if you just supply a cookie jar with curl_setopt
  9. Or losing CDs with millions of people's personal information on them... Seriously, it's like something out of a film.
  10. If you do a search for PHP BB codes you'll find plenty of tutorials. It all comes down to regular expressions, so you could look for some introductory guides to that as well.
  11. That should be an and statement, not or - you cant be both an editor and admin so it it'll always be false. Dont forget the comparison will be case sensitive too.
  12. Yes. It means i'm not hungry anymore.
  13. Like this? $list1 = array("cv1","cv2","cv3"); $list2 = array("cv1s","cv2","cv3d"); foreach($list1 as $v1){ foreach($list2 as $v2){ if(strpos($v2,$v1) !== FALSE){ echo $v1.'<br />'; } } }
  14. I'd do something like this: $str = 'hello'; $char = 'H'; if(strcasecmp($str[0],$char) == 0){ echo 'true'; }else{ echo 'false'; }
  15. Well, you can't make someone download something, can you? I mean, that'd be a pretty big security risk, no? All you can do is offer them the option to download a file or open/run it. If that's what you're after (wasn't sure, your question was a bit ambiguous) then google for php force download. You'll find plenty of information
  16. I have this from a while ago which was used to find a file and then replace some text in it. You could modify if for your needs: <?php function find_file($dir,$file_to_find,$text_to_find,$replacement){ $handler = opendir($dir); while(false !== ($file = readdir($handler))){ if($file != '.' && $file != '..'){ if(is_dir($dir.'/'.$file)){//if this is a directory, recall the function with the subdirectory defined $sub_dir = $dir.'/'.$file; find_file($sub_dir,$file_to_find,$text_to_find,$replacement); }else{ if($file==$file_to_find){//this is the file we are looking for echo 'found'; $new_contents = str_replace($text_to_find,$replacement,file_get_contents($dir.'/'.$file)); $h = fopen($dir.'/'.$file,'w'); fwrite($h,$new_contents); fclose($h); } } } } } echo find_file($_SERVER['DOCUMENT_ROOT'],'test.txt','test','blah'); ?>
  17. Not sure there'll be a tutorial about this. Your best bet is google what you're trying to do, which, in this case, is work out if a file exists. In fact, the function is just that: file_exists()
  18. If you do mean that you'd like to show more than one random link at a time, i'd do it like this: $links[] = 'link one'; $links[] = 'link two'; $links[] = 'link three'; $links[] = 'link four'; function randomlinks($links,$numberoflinks){ if(count($links) < $numberoflinks){ return false; } shuffle($links); for($x=0;$x<$numberoflinks;$x++){ echo $links[$x].'<br />'; } } randomlinks($links,2); If you meant that you'd like to show a different link over time each time a user comes to your site, then it becomes a bit more complicated and you'll need to store what was shown in a database. jonsjava: yours does not ensure all links returned are unique.
  19. The first thing i notice is that you have not called session_start() at the top of the page. You must use this function in your script prior to output and prior to using any session variables(so, the safest and best place is as the first line of your script) and it must be used in all pages that use those session variables. Also, you should really try to indent your code properly. You'll make your life so much easier. Oh, and try to use the tags when you post your code on the forums. Since you're new, I wont berate you for the lack of them in your last post
  20. Sounds like you're going about this the wrong way. You should have the form be submitted, along with the user's attempt at the captcha. The first thing you then do when the form has been submitted is to check the captcha is correct. Assuming it is, you continue to process the rest of the form. If it's not, you stop processing the form and return the user to the form - preferably with the fields filled in with what the user provided (except the captcha - generate a new one).
  21. Surely that's completely the wrong way round? :s March 17 is before march 23 therefore, on march 23, she HAS had her birthday. And vise versa for the t'other example? Anywho, i'd do it like this: $age = 13; $mod = '03';//march - note that this must be a string and must be two digits $dob = '17'; $yob = ('0323' > $mod.$dob) ? 1992 - $age : 1992 - $age - 1; echo $yob;
  22. Well, you've already shown how to store the results in an array with this line: $MID[] = $row['MATRIMONIAL_ID']; The point is that you cannot then echo a value without providing a key. Basically, if you wish to do anything with the variable inside the array then use $row['MATRIMONIAL_ID']. If you do this: $sql = "SELECT * FROM profile where GENDER = 'F' "; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $MID[] = $row['MATRIMONIAL_ID']; } echo '<pre>'.print_r($MID,1).'</pre>'; You will see that the array has been populated.
  23. Try the MySQL DATE_FORMAT function.
  24. The problem is that PHP does not know which element of the array you are trying to echo. You are correct that it can add to an array without specifying the key - it just uses the next available number. However, when you read from an array, you must specify the key. If you're trying to echo something in the loop, use $row['MATRIMONIAL_ID'].
×
×
  • 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.