-
Posts
579 -
Joined
-
Last visited
Posts posted by Drongo_III
-
-
You could change header location on the page that processes your form data.
So once it's done all of the processing (and assuming it doesn't output anything to the page) do:
<?php header('Location: http//www.YourFormPageLink.com'); ?>
And that'll redirect them anywhere you want.
Alternatively if you don't know precisely what page they originated from then you could grab the url of the form page and set it as part a session variable or post it with the form. Then use that data in your header location to send them back to that link.
Hi guys,
Is it possible to make a page automatically redirect to the previous page a user was in once they submit a form?
Thanks
-
If your images originate from an array how about:
<?php //Do you array count to get number of values and set this to count $img= array(); //images array $img[] = "image1"; $img[] = "image2"; $img[] = "image3"; $img[] = "image4"; $img[] = "image5"; $img[] = "image6"; $img[] = "image7"; $img[] = "image8"; $img[] = "image9"; $img[] = "image10"; $img[] = "image11"; $img[] = "image12"; $count= count($img); echo "$count"; for ($i=0; $i<$count; $i++){ if ( $i==0){ echo "<div>"; } if ($i % 5 == 0 && !$i == 0){ echo "</div> <div>"; } echo $img[$i]; } echo "</div>"; ?>
-
Well you could change it so it matches the class as a literal and then it would only target that div.
Didn't know pattern_order was the default. I've always used it just for the sake of it. I've only used regular expressions for pretty basic stuff to be honest.
Thanks for the tip
@Drongo_III
There's no need to pass the PREG_PATTERN_ORDER flag, it's the default. Though your pattern would match all DIVs with just a class attribute, so it's not really a practical solution.
@hamza
I think your problem is using ^ and $ at the start/end of the pattern. Together these require that the pattern is the *only* contents of the string. You can omit either or both to remove that restriction from one or both sides of the pattern.
-
Or that lol...
$str = str_replace("\n", "", $str);
-
You could use:
$string = 'The older way of doing this, with gconftool-2 doesn’t seem to work anymore in GNOME 3 – used to be something like:<br /><br />However, there is still possible to change the background image, by using the gsettings tool instead. You will need the libglib2.0-bin package, which is probably already installed on your system. To change the background, use a command like the following:'; $patterns = array(); $patterns[0] = '|<br /><br />|'; $replacements = array(); $replacements[2] = ''; echo preg_replace($patterns, $replacements, $string);
That will remove any insteance of your double line break. However, if you're going to use it a bit more widely then you might want to make the regular expression a bit cleverer in that it will currently match precisely the way
<br /><br />
is written - spaces and all.
But should set you on the right path
-
Hi Mate you could try this
$teststring = "This is a new string \n and i just out a line in"; echo nl2br($teststring);
It replaces all new lines with html line breaks
-
I changed what you used slightly but this will match both your class and the content of the div
preg_match_all("|<div class='(.*?)'>(.*?)</div>|", "<div class='mainful'>this is testing of the string n thats it </div>", $out, PREG_PATTERN_ORDER); echo "<pre>"; print_r($out);
I need to get the content of this div.
but getting nothing
$str = "<div class='mainful'>this is testing of the string n thats it </div>"; $str = preg_quote($str, "/"); $result = preg_match_all("/^<div class=\/'mainful\/'>(.*?)<\/div>$/", $str , $matches_results); if($result){ print_r($matches_results); exit; } else { echo "no match "; }
-
Hi shadow
This is quite hard to wrap your head around.
The reason the order works like that can be shown with a normal variable.
For instance:
var1 = "TIM"; var1 = "My name is $var1"; echo var1; // Will echo "My name is TIM"
I believe the reason this happens is because before the system assigns the new variable name to the second $var1 it's saying - "right, what does the value of the second var1 need to be?" And in this case its seeing a string "MY name is" followed by a variable (the first instance of $var1). So it evaluates that part of the statement - i.e. The new value for $var1 should be "My name is Tim" and then it overwrites the value held for $var1.
I think it's important to understand that is the way variables work and not to confuse it as a quirk of references
At least that's my understanding of it...
Thanks alot marcelobm for the reply
why wouldnt it echo bob first before My name is?
outputing Bob My name is
why does $bar = &$foo go ahead of 'Bob'
-
Hi shadow
This is quite hard to wrap your head around.
The reason the order works like that can be shown with a normal variable.
For instance:
var1 = "TIM"; var1 = "My name is $var1"; echo var1; // Will echo "My name is TIM"
I believe the reason this happens is because before the system assigns the new variable name to the second $var1 it's saying - "right, what does the value of the second var1 need to be?" And in this case its seeing a string "MY name is" followed by a variable (the first instance of $var1). So it evaluates that part of the statement - i.e. The new value for $var1 should be "My name is Tim" and then it overwrites the value held for $var1.
At least that's my understanding of it...
Thanks alot marcelobm for the reply
why wouldnt it echo bob first before My name is?
outputing Bob My name is
why does $bar = &$foo go ahead of 'Bob'
-
Hi mate
Try this as the pattern:
$patterns[0] = '/[^\w@.]/';
essentially that pattern means replace everything except what is inside the square brackets.
The \w applies too all letters, numbers and the underscore. If you also want to add in a hyphen as an allowed character then use:
$patterns[0] = '/[^\w@.\-]/';
Hope that helps matie I have had a good refresher in simple regex today hehe
-
Better version
$string = 'John_Smith 533r3r3 >>>'; $patterns = array(); $patterns[0] = '/[^\w]/'; $replacements = array(); $replacements[0] = ''; echo preg_replace($patterns, $replacements, $string);
This replaces everything except letters, numbers or underscores.
-
Hmm
I would try something like
$string = 'John_Smith fee334343'; // This is the pattern the pre_replace will use looking for matches $patterns = array(); $patterns[0] = '/[ \-_]/'; // The array value here that corresponds to the above pattern will replace matches //with the contents of the array value. So in this case it replaces anything found //in the pattern with '' - i.e. removes spaces, hyphens etc. $replacements = array(); $replacements[0] = ''; echo preg_replace($patterns, $replacements, $string);
Great, thanks, I thought it looked long just to do a simple check, but it worked so I was happy with that!
Thanks again.
Also, have you any idea how to remove everything from a string except letters, numbers and the @ sign,
so:
"hello123-123" = "hello123123"
"John o'Leary" = "John oLeary"
"aaaaaa11111111_1111@" = "aaaaaa111111111111@"
Thanks again.
-
Hi mate
Err I was having a fiddle with this and a much more simpler version would be:
<?php $pattern5 = '/[\w]?[\d]+/'; $email = '111eeee'; if (preg_match($pattern5, $email)) { echo "your pattern matched"; } else { echo "Your patten didn't match"; } ?>
That is a much simpler way of matching alphanumeric characters or just numeric. It won't match just letters though. Sorry looked at regex sooo long ago that i thought it needed to be a lot more complicated than it did!
-
Hi mate
Ok this is testing my limited regex knowledge to the limits here but i think this works:
<?php $pattern2 = '/^(?=.*\d)|(?=.*\d)(?=.*[a-zA-Z]).{1,}$/'; $email = 'uhuuyyv576576576'; if (preg_match($pattern2, $email)) { echo "your pattern matched"; } else { echo "Your patten didn;t match"; } ?>
It should match any pattern of letters and number, or just number but it won't match just letters...hehe confusing myself now...
-
I think if you just want to match a single charcter you're over complicating it using regex.
Try this:
<?php $email = '[email protected]'; if (strstr($email, '@')) { echo "your pattern matched"; } else { echo "Your patten didn't match"; } ?>
-
Yeah it's really hard one mate. I would just try simplifying the query in your function to try and get it working so you can identify the problem. That's about all i can suggest at the mo :/ There are greater php minds here than mine tho so sure someone can help ya
-
Oh sorry didn't see that bit. Mmm then i am a bit stuck on this one too :/
-
Ok.
Well first thing is to fix that error.
Have you tried removing the
mysql_real_escape_string($question)); // THIS IS LINE 177
from that line of code and seeing if it works then? That line is looking for a variable $question that hasn't been assigned yet (at least that's how the logic goes in my head). I would start by removing that and seeing what you get.
-
Well I think when its parsed the system essentially looks for an opening { and if no other { is found then the next } is considered the closing one. Whereas is two { { are found then it will look for the next }} to close. That make more sense hehe?
Thanks for the reply
The part that I dont understand or cant wrap my head around is that how does the script know which } to what statement it belongs too? Notice at the end of my code it has several }.
what really confuses me the most is the two } above this line
$_SESSION['user_id'] = $row['id'];// this line of code is very important. This saves the user id in the php session so we can use it in the game to display information to the user.
Jedit is telling me those two } goes with the statements just above it but how does the code know its not for the statements at the begining of the script that ends at the end of the script.
This is really hard to explain on what is confusing me hope i explained it. I really need help understanding this cause its like the only thing left that really has me confused on PHP
-
Bit hard to say without seeing the code in it's entirety i'd say. But yeah if you have session start at the top and it's the first thing then that should be ok.
First off i would ensure you're getting data from your query.
So comment out your session bit and just try echoing your $row[0] to make sure that bit is ok.
Can you post more of the code and the function you start your session in?
The function is in a separat file, and when i add session_start() in the very beginning, it gives me an error saying, that the session already is started, therefore, there is session_start() in the top.
Is that wrong?
-
Couple of things:
1) did you start the session? Can;t see that in your code.
2)Before you set the session variable have you tried just echoing the query results to make sure you're getting data? Sorry if i'm stating the obvious.
Thank you very much, but it doesn't work.
$query = "SELECT question FROM registertest ORDER BY RAND() LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } $row = mysql_fetch_row($result); $_SESSION['registertestquestion'] = $row[0]; return $row;
The session part is because i need it later again.
At this point, it returns nothing?
-
-
Ahh sry wasn't trying to be pedantic i was just wondering if i was doing something wrong...as seems to happen every ten lines of code i write haha
yes, my bad.. You are supposed to compare it to zero.
IOW, $count % 4 == 0
-
Sorry the reason i asked my question is because I thought you had to say something like
if ($count % 4 == 0) { // Do the new line } When I tried using just [code] if($count % 4){ // Do the new line }
It didn't work for me and just echoes the new line constantly :/ So trying to figure out if I'm doing something wrong or misundestanding the way it works. Or whether the code should have ==0 for this sort of function.
For this effect you use the modulus operator along with a counter
Example, using part of your code
$count = 0; while($tir = mysql_fetch_array($tiquery)) { $tiid = $tir['itemid']; $tin = $tir['name']; $tiim = $tir['image']; $tid = $tir['description']; echo "<img src=/images/items/$tiim>"; if($count % 4) echo "<br />\n"; $count++; }
php redirect automatically to the previous page
in PHP Coding Help
Posted
You would probably need to start a session to track the user if you wanted to do that. Then have some logic to determine the page visited before the form page. At least that would be my first guess at how to do it.
You'd essentially just keep overwriting the same session variable for every page unless the user is on the form page where it would pull the page variable instead of overwriting it- which would at that point be set to the last page visited.
Although someone might suggest a better way of doing it.