-
Posts
2,527 -
Joined
-
Last visited
Posts posted by DeanWhitehouse
-
-
No, not yet, found a bug
this code
if(preg_match('/\[user=(.*?)\]/s', $code, $regs)) { $sql = mysql_query("SELECT username FROM user_details WHERE username = '".mysql_real_escape_string($regs[1])."'"); $user = mysql_fetch_assoc($sql); if(mysql_num_rows($sql) == 0) $code = preg_replace("/\[user=(.*?)\]/s","\\1",$code); else { $code = preg_replace("/\[user=(.*?)\]/s",CreateUserLink(null,$user['username']),$code); } } if(preg_match('/\[user\](.*?)\[\/user\]/s', $code, $regs)) { $sql = mysql_query("SELECT username FROM user_details WHERE username = '".mysql_real_escape_string($regs[1])."'"); $user = mysql_fetch_assoc($sql); if(mysql_num_rows($sql) == 0) $code = preg_replace("/\[user\](.*?)\[\/user\]/s","\\1",$code); else { $code = preg_replace("/\[user\](.*?)\[\/user\]/s",CreateUserLink(null,$user['username']),$code); } }
when i do
[user]blade280891[/user]
[user]protestthehero[/user]
[user=blade280891]
[user=protestthehero]
It makes four links which is correct, but the second and last link is to the first one if that makes sense . SO the above prints
Blade280891
Blade280891
Blade280891
Blade280891
Any ideas?
-
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);
-
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
-
Have you tried the phpfreaks tutorial on it?
-
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
-
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
-
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);
-
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?
-
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
-
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)
-
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
-
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?";
-
I had a design made for me, http://www.weddings.djw-designs.com/ , but i found out that when i added my own links etc. the design fell apart.
I need this site design redone tonight latest, i need a css coder who can make this site look and work great, the content will be dynamic so i need a flexible design.
Please PM me asap
-
Ok, i will look over it when i get back, it is using php mailer
-
@Malevolence
Except it is considered bad practice to use PHP short tags
-
@redarrow, whitespace problems occur with HTML whitespace not PHP whitespace.
Also
Ahh well...first of all, I notice that you're checking if the form has been submitted by using if(isset($_POST['submit'])) which I assume is the submit button. The only problem with this is that if you don't actually click the submit button, ie you just press enter, it is ignored.
So yeah, are you sure the form is actually being submitted?
And also, maybe try simply echoing the contents of your sessions, to see if they are actually set or not...?
Are you serious ??
Try it, using if(isset($_POST['submit_button'])) works if you press the button or if you press the enter key.
-
-
-
lol
You might want to try code before asking for help with it
-
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");
-
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.
-
Make sure both use utf-8 charset encoding
-
Read through the security tutorial on this site, it covers that i believe.
-
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.
[SOLVED] Regex, or str_ireplace?
in Regex Help
Posted
I need it to act like bbcode, so that it replaces each one seperatly
e.g.
User1 and user2 need to be links which to there profiles,clearer?