Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
This...
header("Location: fichaTorneioFinSub.php?id=" . $_GET['id'] . "");
The value of the GET is 1. But I always end up in this page:
fichaTorneioFin.php?id=%271%27
The id value gets these %27 around it. I know that means it's an encoded single quote but it shouldn't be there.
It would be a good idea to track down what's giving you the lone ', but this will ensure you're only working with digits:
$id = preg_replace('/\D/', '', $_GET['id']);
header("Location: fichaTorneioFinSub.php?id=".$id);
This will sound as stating the obvious: if it shouldnt be there, make sure it isnt. This means sanitizing your input ($_get data) into data you expect. Somehow the get variable already contains a single quote so i would suggest checking that first. To get it out you could for example
trim($_get ['id'], "'")
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have code like this
function get_id(){
return 1;
//
}
I want to remove all // inside the source code, but only those stand by it own, on a newline just like the example here. Nothing much nothing more. How can I do it?
Search using this regex:
^\s*\/\/\s*$
and replace by empty string.
If using PHP you can use \h (horizontal space) instead of \s:
$code = preg_replace('~^\h*//\h*$~m', '', $code);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to use PHP to find a value in a string and replace it with another value, the value may be (for example) £x on one line and £x.xx on the next, but will always be replaced by a value of £x.xx. Hope that makes sense? TIA.
Use this regex to match the prices: £[0-9]+\.?[0-9]{0,2}
You can perform the replace with this by using this function:
preg_replace("/£[0-9]+\.?[0-9]{0,2}/", " ** REPLACEMENT ** ", $input_lines);
The nice thing about preg_replace is that if you feed it a single line you'll get a single value back, but if you feed it an array of strings with the values you want changed it will return an array with those values replaces. Nice and tidy if you need to make a lot of replacements.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Example:
http://mysite.domain/user1 //profile user 1
http://mysite.domain/user1/photos //photos user 1
http://mysite.domain/user1/friends //friends user 1
Action of user only photos or friends.This is my code:
if (preg_match('/^\/([\w\-]+)(\/[photos|friends]+)$/i', $url, $m)) {
//code...
}
But not working, somebody can help me?
One error is [photos|friends]+. This will match too broadly, namely any combination of the characters mentioned, including |; not the whole string in the order you put it (either 'photos' or 'profile').
I think what you want for the expression is '/^\/([\w\-]+)\/(photos|friends)$/i' — that’s assuming $url is '/user1/photos' or '/user1/friends'.
I would suggest when matching URLs to use a regex delimiter other than /, because having to escape all the slashes makes the expression hard to comprehend. Personally, I like to use the comma (as it’s rather rare in URLs): ',^/([\w\-]+)/(photos|friends)$,i'.
Update
To make the last part (/photos or /friends) optional, use ',^/([\w\-]+)(/(photos|friends))?$,i'. If you want to allow /user1/ (with the trailing slash), you can keep it even simpler ',^/([\w\-]+)/(photos|friends)?$,i'.
The ? will make the preceeding token optional (in the first case, this is (/(photos|friends)), in the second case, it’s just (photos|friends).
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I pass a variable called txt from one query on a web page to another web page using
<?php echo $_GET['txt'];?>
the problem some time the text will have a word like don't in it. the (') causes things to just stop. I need to output the variable as read from the database which would include any text that was in the field
When using $_GET you should use urlencode() and urldecode().
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I did something wrong because the last lane do not add anything to database.
Could someone experienced take a look please?
EDIT: I just deleted all unnecessary lanes
mysql_query('INSERT INTO votes (voter, photoid, photoowner, vote) VALUES ($voter, $photoid, $photoowner, "yes")');
Variable values are not evaluated within a string with single quotes:
mysql_query("INSERT INTO votes (voter, photoid, photoowner, vote) VALUES ('$voter', '$photoid', '$photoowner', 'yes')");
put double quotes around your select statement or use concatenation and don't forget to put quotes around your string values
Also use use mysql_error() to retrieve the error text