btherl
Staff Alumni-
Posts
3,893 -
Joined
-
Last visited
Everything posted by btherl
-
Is it possible to embed php within a javascript function like below ?
btherl replied to jd2007's topic in PHP Coding Help
The same way you use php to construct html. There's a few different styles of that. For example print '<script type="text/javascript">"; print 'alert('Hi there');'; print '</script>'; -
Is it possible to embed php within a javascript function like below ?
btherl replied to jd2007's topic in PHP Coding Help
Hmm. You cannot have php code that executes within javascript. But you can use php to dynamically generate code that is later executed by javascript. If you want to execute php code after the javascript has begun execution, then you need to use ajax techniques to call the php code on the server. The reason for all this is that php is server side and javascript is client side (it runs in your browser). -
Getting time of day from Unix timestamp - somewhat iffy
btherl replied to deadimp's topic in PHP Coding Help
I've read your description and your code and I still don't understand ??? Can you post an example of the date format you are using, and point out the problems with it? -
The functions you listed are fine for UTF8 in MOST cases. UTF8 extends ascii by using characters with the high bit set, so as long as you are dealing only with the standard ascii character set, you are ok. Basically, most functions will treat your utf8 extended characters as binary data and ignore them. For example, stripslashes() deals with the character '\', which is standard ascii, so it is safe. But calling trim() to trim a character above 0x7f may corrupt your UTF8. Standard trim() is fine Functions like mysql_real_escape_string() are binary-safe, so you do not need to worry what encoding you are using. binary safe - mysql_real_escape_string() http://il2.php.net/manual/en/function.mysql-real-escape-string.php safe - stripslashes() http://il2.php.net/manual/en/function.stripslashes.php ? - addslashes() http://il2.php.net/manual/en/function.addslashes.php safe - strstr() http://il2.php.net/manual/en/function.strstr.php safe for input < 0x7f - trim() http://il2.php.net/manual/en/function.trim.php ? probably safe - wordwrap() http://il2.php.net/manual/en/function.wordwrap.php safe - vsprintf() http://il2.php.net/manual/en/function.vsprintf.php safe - nl2br() http://il.php.net/manual/en/function.nl2br.php I don't think addslashes makes much sense on UTF8. I would avoid it if possible. Whatever you use addslashes for can be replaced with more specific escaping. Note that trim() will only trim ascii whitespace, and will not trim any UTF8 characters that are "whitespace". You'll have to do that yourself if you happen to have some of those.
-
User edit update problems due to md5 encryption
btherl replied to flashguy82's topic in PHP Coding Help
What code do you use to check the password? Make sure you include any processing done to the inputs, such as stripslashes() -
Can you try this out? <script type="text/javascript"> function refresh_parent() { window.parent.location.href = window.parent.location.href; }</script> Then you can call that javascript function somewhere in your iframe. For example: <input type=button onclick='refresh_parent()'> Not sure if that will work.. and it may not be browser independent, but it's worth a try!
-
[SOLVED] Making mysql result into multi-dimensional array
btherl replied to themeatpuppet's topic in PHP Coding Help
It looks to me like you are adding the castle to the castles array based on $prev_proi, which increments every time through the loop. Instead, you should add the castle inside the first if statement. In fact, you can do everything in there - Put guards in the castle, and put castle in the castle list. Then you empty out the castle and guard lists and initialize them for the new castle (which is in the current loop iteration). If (new castle) { Put guards in the castle Put castle in the castle list Initialize new castle and guard lists } if (new guard) { Put guard in the guard list } There's no need to put the guards in the castle when finding a new guard, only when finding a new castle. -
Did you use a user-defined function to find jdelacruz? If so, alter that function to return the array key as well. If you want us to help, post your current code.
-
[SOLVED] Adding a string to the end of a varibale name.
btherl replied to Splash's topic in PHP Coding Help
Sorry, I'm tripping.. I meant to say $$varname = 'Value'; -
If Berkeley DB is available you can use that. You can also store the data in text files if all else fails.. but how you structure those depends very much on what data you need to store, and how you want to access it. Berkeley db info here: http://sg.php.net/manual/en/ref.dba.php
-
Those are generated by the browser, not the script.. the only way to stop them is to ask the user to switch them off.
-
[SOLVED] Adding a string to the end of a varibale name.
btherl replied to Splash's topic in PHP Coding Help
You can do this: $n = 1; $varname = 'Variable' . $n; $$n = 'Value'; print $Variable1; The "$$" is what allows it to work. The other option is using eval(), but there's no need for that in this case. -
Ooh, you want your iframe to trigger the parent's reload. No it can't be done with headers, but i am pretty sure it can be done with javascript. Unfortunately I'm hazy on how it works. A google for "iframe access parent" turns up sites like this: http://www.esqsoft.com/javascript_examples/iframe_talks_to_parent/ The value you want to set is probably "document.parent.location".. again I am hazy on that. "iframe refresh parent" also shows up useful stuff in google.
-
If you are trying to refresh the page without refreshing the iframe, then no that is not possible. An iframe is "part of" the main page. But I see no reason why you cannot use the location header early to abort the current page processing, and redirect to the alternate page which has everything you want. btw, relative "location" headers are not standard, so it's safer to give a full url instead (you can extract the correct url from $_SERVER variables). Another option you may consider is using javascript to edit the div and put the name there. Javascript can edit any virtually any part of a page without requiring a reload.
-
[SOLVED] Making mysql result into multi-dimensional array
btherl replied to themeatpuppet's topic in PHP Coding Help
Hi! Actually the method you are using for dup detection is what I use all the time. I don't think there is any more elegant way. Just remember that the final item will must be added manually following the loop! Because the test against the previous item is not made for the final item, as there is nothing following it .. while (get a row) { if (row != previous row) { add to array } } Add final row to array Also I notice you have no "order by" in your sql. That's essential if you're going to do duplicate detection like that. The order by should match the structure you are building. If you want the array to be associative, use something like $castles[$cn] = $castle instead of array_push(). Apart from that, the idea is sound, so I am sure you will get it working! -
This works for me: $url = 'http://www.youtube.com/watch?v=kP5rpxEhTsw'; if(!preg_match("~http://www.youtube.com/watch\?v=\w+~", $url)){ print "Failure \n"; } else { print "Success :)\n"; }
-
[SOLVED] Pagination Script... What's wrong with it?
btherl replied to Foser's topic in PHP Coding Help
$num = $max_value -$min_value + 1; $query1 = mysql_query("SELECT * FROM pagination ORDER BY id LIMIT $min_value, $num"); while ($row = mysql_fetch_assoc($query1)){ echo "ID Number: {$row['id']}<br>Name: {$row['name']}<br>Age: {$row['age']}<br>Referer: {$row['referer']}<br>-----------------------------------------------------<br>"; } Give that a try and let us know how it goes. My mysql syntax is a bit rusty, as i'm a postgres user. -
Ok, makes sense. Does it really matter if the user refreshes, since the user never knows what the computer has guessed? If you don't want the guess to change, you could do something like this: if (user made a guess) { Check guess Update score Generate new guess } else { Do nothing. Keep the old guess. }
-
[SOLVED] Pagination Script... What's wrong with it?
btherl replied to Foser's topic in PHP Coding Help
When a function returns a value, you need to set that value to a variable. For example: $max_value = max_ammount($getpage,2); $min_value = next_number($getpage); -
We can't give you any more detailed help unless you describe your game's structure in more detail. You can reset the session counter any time you want. Just $_SESSION['counter'] = 0.
-
Try printing out this: print urlencode($_POST['headline']); \r will show up as %0d, and \n will show up as %0a. Then check to see if it's what you expect. You might want to look at nl2br() as well. You can always strip out the \n and \r after using nl2br().
-
No output being sent until function has finished
btherl replied to agravayne's topic in PHP Coding Help
Compression (such as mod_gzip or zlib.output_compression) will buffer output, even if php is not buffering it. Even if you have zlib output compression enabled in the config but disable it at runtime, your output will STILL be buffered. You might want to try ob_implicit_flush() if you haven't already.. -
Best way to prevent refresh rerunning php code in script
btherl replied to jwhite68's topic in PHP Coding Help
The simplest method I can think of is to set a session variable. If you're not familiar with sessions, it's time to learn They are very useful things. If you set the session variable when the form is first submitted, then you can test it the second time and recognize that something is awry. -
Suggestion 3: parse_str($string, &$array); print_r($array);
-
The SORT_NUMERIC option should do the trick.. http://sg2.php.net/manual/en/function.array-multisort.php