Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by DeanWhitehouse

  1. Sorry , i tried to only show code which applied to keep it simple, but this code is inside one bigger function which is then inside another function. So here is the bbcode function <?php Removed ?> The output i need is a link to the users profile, the function createuserlink will create a link to the profile based on username or userid. the function createuserlink has these arguments function CreateUserLink($userid = null,$username = null) if $userid is null then it creates one using $username Scrap all that, solved i just needed to change $code = preg_replace("/\[user=(.*?)\]/s",CreateUserLink(null,"\\1",$code); to $code = preg_replace("/\[user=(.*?)\]/s",CreateUserLink(null,$regs[1]),$code);
  2. Not working, i tried this if(preg_match('/\[user=(.*?)\]/s', $code, $regs)) { $sql = mysql_query("SELECT id FROM user_details WHERE username = '".mysql_real_escape_string($regs[1])."'"); if(mysql_num_rows($sql) == 0) $code = preg_replace("/\[user=(.*?)\]/s","\\1",$code); else { $code = preg_replace("/\[user=(.*?)\]/s",CreateUserLink("\\1"),$code); } } The bit where the link should be is empty
  3. Have you tried the phpfreaks tutorial on it?
  4. No that code is fine, the fact is that after debugging i found out that the sql query is returning 0 rows although if i do it myself it doesn't, this is because i believe all the other text in the $code var is being sent as well, not just the bit i need
  5. Never mind, but i have got this now $code = preg_replace("/\[user=(.*?)\]/s","\\1",$code); $sql = mysql_query("SELECT id FROM user_details WHERE username = '".mysql_real_escape_string($code)."'") or die(mysql_error()); if(mysql_num_rows($sql) == 0) $code = $code; else { $code = CreateUserLink($code); } But it isn't creating the link :s
  6. Ok, so i am going to use a user tag e.g. [user = ] but what do i do to find the user? Cus i have $code = preg_replace("/\[user=(.*?)\]","<a href=\"profile.php?user=\\1\" target=\"_blank\">\\1</a>",$code);
  7. Thats the solution i thought off but i am worried about speed issues as there could be a lot of users in the db. I was thinking that it would loop through each user name and check the text for that username and replace it, but i assume this can be very slow?
  8. Hi again i have a little coding problem, regarding regex, i want to write a code that is like bbcode but searches for user names in the content and replaces them with profile links, any idea how i can do this using regex?? Is it possible with regex, or shall i use something like a loop with str replace
  9. Still not working, and "Straight variable comparison would be easier; " not possible as i need a list of unaval steals, which a var can't have (not simply) Jons thanks, clever way to do it wouldn't of ever thought of that, topic solved (as far as i can tell)
  10. The sql would be better, i will change that and Mark, no i am not, please show me an example in my code where i am
  11. Hiya, Long time since i have posted a coding problem, but here it goes. I have created this code to work out what a user can steal from another user, but it seems to allow the user to try and steal anything even if it is on the list of unstealable items, any ideas as to why? Does in_array return a different value than i thought? Code Snippet function StealType($extort) { $car = mysql_query("SELECT id FROM user_cars WHERE user_id = '".$extort['id']."' AND up_for_sale = '0' ORDER BY RAND() LIMIT 1"); $cash = mysql_query("SELECT money FROM user_stats WHERE user_id = '".$extort['id']."' LIMIT 1"); $c_check = mysql_fetch_assoc($cash); $bullets = mysql_query("SELECT bullets FROM user_stats WHERE user_id = '".$extort['id']."' LIMIT 1"); $b_check = mysql_fetch_assoc($bullets); $Not = array(); if(mysql_num_rows($car) == 0) { $Not[] = 1; } if($c_check['money'] < 100) { $Not[] = 2; } if($b_check['bullets'] == 0) { $Not[] = 3; } print_r($Not); if(in_array(array(1,2,3),$Not)) { echo "S1"; return false; } elseif(!in_array(array(1,2,3),$Not)) { echo "S2"; return rand(1,3); } elseif(!in_array(array(1),$Not) && in_array(array(2,3),$Not)) { echo "S3"; return 1; } elseif(!in_array(array(2),$Not) && in_array(array(1,3),$Not)) { echo "S4"; return 2; } elseif(!in_array(array(3),$Not) && in_array(array(1,2),$Not)) { echo "S5"; return 3; } elseif(!in_array(array(1,2),$Not) && in_array(array(3),$Not)) { echo "S6"; return rand(1,2); } elseif(!in_array(array(1,3),$Not) && in_array(array(2),$Not)) { echo "S7"; return 1; } elseif(!in_array(array(2,3),$Not) && in_array(array(1),$Not)) { echo "S8"; return rand(2,3); } } $steal = StealType($extort); if($steal == false) { echo "Failed! This user has nothing!"; } elseif($steal == 1) { echo "To come car"; } elseif($steal == 2) { echo "To come cash"; } elseif($steal == 3) { echo "To come bullets"; } else echo "Error! What the fuck?";
  12. Ok, i will look over it when i get back, it is using php mailer
  13. @Malevolence Except it is considered bad practice to use PHP short tags
  14. @redarrow, whitespace problems occur with HTML whitespace not PHP whitespace. Also Are you serious ?? Try it, using if(isset($_POST['submit_button'])) works if you press the button or if you press the enter key.
  15. lol You might want to try code before asking for help with it
  16. No one here will want to copy your code, if we can help fix it we can most likely create it ourselves. Here is what the code might be like mail($_POST['email'],"Thanks","Thank you for signing up","From: myemail@mysite.com");
  17. you don't need to do that for all variables, but if you have messy code and/or cannot tell if the variable has been set then do that.
  18. Make sure both use utf-8 charset encoding
  19. Read through the security tutorial on this site, it covers that i believe.
  20. It is bad practice to ignore or suppress errors (although some must be suppressed), and bad practice to turn error reporting off while developing, if the site is developed you should develop your own error reporter.
  21. Do not ignore the errors, or turn them off (while developing), fix them, it will make you a better coder and make the code better. All you need to do is make sure that all the variables are defined before using them. E.g. if(!isset($Var)) $Var = "";
  22. What bit? The saving the image bit? If so then i think this will either need to be done manually or using file_get_contents maybe, with some php image functions to create an image from the image. I am just throwing some ideas around
  • 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.