blinky001
-
Posts
29 -
Joined
-
Last visited
Posts posted by blinky001
-
-
Afraid I've never tried to do this in PHP, but I did have a go starting from someone elses script once in JS, sadly my Zelda clone was too boring to work on for very long...
//pathFinder.js function pathFinder(grid) { this.grid = grid; this.cols = grid[0].length; this.rows = grid.length; this.limit = this.cols * this.rows; } pathFinder.prototype = { // Variables --------------------------------------------------------- grid: new Array(), start: new Array(), end: new Array(), cols: 0, rows: 0, limit: 0, // Returns boolean value (Grid cell is available and open) inGrid: function(x, y) { return this.grid[y][x] === 1; }, // Node function, returns a new object with Node properties node: function(parent, point) { return { parent: parent, value: point.x + (point.y * this.cols), x: point.x, y: point.y, f: 0, g: 0 }; }, calculatePath: function(start, end) { this.start = start; this.end = end; var startNode = this.node(null, {x:this.start[0], y:this.start[1]}), endNode = this.node(null, {x:this.end[0], y:this.end[1]}), AStar = new Array(this.limit), openArray = [startNode], closedArray = [], resultArray = [], successorNodes, currentNode, pathNodes, length, max, min, i, j; while(length = openArray.length) { max = this.limit; min = -1; for(i = 0; i < length; i++) { if(openArray[i].f < max) { max = openArray[i].f; min = i; } } currentNode = openArray.splice(min, 1)[0]; if(currentNode.value === endNode.value) { pathNodes = closedArray[closedArray.push(pathNodes) - 1]; do { resultArray.push([pathNodes.x, pathNodes.y]); } while(pathNodes = pathNodes.parent); AStar = closedArray = openArray = []; resultArray.reverse(); } else { successorNodes = this.successors(currentNode.x, currentNode.y); for(i = 0, j = successorNodes.length; i < j; i++) { pathNodes = this.node(currentNode, successorNodes[i]); if(!AStar[pathNodes.value]) { pathNodes.g = currentNode.g + this.manhattan(successorNodes[i], currentNode); pathNodes.f = pathNodes.g + this.manhattan(successorNodes[i], endNode); openArray.push(pathNodes); AStar[pathNodes.value] = true; } } closedArray.push(currentNode); } } return resultArray; }, // Find adjacent available cells - returns every available North, South, East or West cell successors: function(x, y) { var N = y - 1, S = y + 1, E = x + 1, W = x - 1, $N = N > -1 && this.inGrid(x, N), $S = S < this.rows && this.inGrid(x, S), $E = E < this.cols && this.inGrid(E, y), $W = W > -1 && this.inGrid(W, y), result = []; if($N) { result.push({x:x, y:N}); } if($E) { result.push({x:E, y:y}); } if($S) { result.push({x:x, y:S}); } if($W) { result.push({x:W, y:y}); } //this.diagonalSuccessors($N, $S, $E, $W, N, S, E, W, result); return result; }, diagonalSuccessors: function($N, $S, $E, $W, N, S, E, W, result) { if($N) { if($E && this.inGrid(E, N)) { result.push({x:E, y:N}); } if($W && this.inGrid(W, N)) { result.push({x:W, y:N}); } } if($S) { if($E && this.inGrid(E, S)) { result.push({x:E, y:S}); } if($W && this.inGrid(W, S)) { result.push({x:W, y:S}); } } }, diagonalSuccessors$: function($N, $S, $E, $W, N, S, E, W, result) { $N = N > -1; $S = S < this.rows; $E = E < this.cols; $W = W > -1; if($E) { if($N && this.inGrid(E, N)) { result.push({x:E, y:N}); } if($S && this.inGrid(E, S)) { result.push({x:E, y:S}); } } if($W) { if($N && this.inGrid(W, N)) { result.push({x:W, y:N}); } if($S && this.inGrid(W, S)) { result.push({x:W, y:S}); } } }, // Distance functions, returns ideal distance from 2 points diagonal: function(point, end) { // diagonal movement return Math.max(Math.abs(Point.x - end.x), Math.abs(Point.y - end.y)); }, euclidean: function(point, end) { // diagonal movement using Euclide (AC = sqrt(AB^2 + BC^2)) // where AB = x2 - x1 and BC = y2 - y1 and AC will be [x3, y3] return Math.sqrt(Math.pow(point.x - end.x, 2) + Math.pow(point.y - end.y, 2)); }, manhattan: function(point, end) { // linear movement return Math.abs(point.x - end.x) + Math.abs(point.y - end.y); } }
and usage test:
//pathFinderDemo.js window.onload = function() { var movementMap = [ [1, 1, 0, 1, 1, 1], [1, 1, 0, 1, 0, 1], [1, 1, 0, 1, 0, 1], [1, 1, 0, 1, 0, 1], [1, 1, 1, 1, 0, 1], ]; for(y = 0; y < movementMap.length; y++) { // Loop Width for(x = 0; x < movementMap[0].length; x++) { var element = document.createElement('div'); element.style.position = 'absolute'; element.style.left = (x * 32) + 'px'; element.style.top = (y * 32) + 'px'; element.style.width = 32 + 'px'; element.style.height = 32 + 'px'; element.id = x + '_' + y; if(movementMap[y][x] == 1) { element.style.backgroundColor = 'blue'; } else { element.style.backgroundColor = 'red'; } document.getElementById('map').appendChild(element); } } var startPoint = [0, 2]; var endPoint = [5, 4]; if(path = new pathFinder(movementMap)) { result = path.calculatePath(startPoint, endPoint, 'Manhattan'); if(result.length == 0) { alert('damn'); } else { for(var i = 0; i < result.length; i++) { x = result[i][0]; y = result[i][1]; var element = document.createElement('div'); element.style.position = 'absolute'; element.style.left = (x * 32) + 'px'; element.style.top = (y * 32) + 'px'; element.style.width = 32 + 'px'; element.style.height = 32 + 'px'; element.id = 'p_' + x + '_' + y; element.style.backgroundColor = 'green'; element.style.textAlign = 'center'; element.innerHTML = i + 1; document.getElementById('map').appendChild(element); } } } }
and the basic html to let you see it:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> Pathfinder Demo </title> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <script src="pathFinder.js" type="text/javascript"></script> <script src="pathFinderDemo.js" type="text/javascript"></script> </head> <body> <div id="map"></div> </body> </html>
-
Seems that this isn't the right place for this post - any chane an admin could wing it over to the 3rd party scripts section (sorry - new to the board)
-
Classes are pretty simple... If you have a directory for includes just make a new file and put in that class info. Then include and use it. E.g.
<?php include('../includes/core.php'); include('../includes/timing.php'); $timer = new Timer(); # All the rest of your page here echo $timer->getTime(); ?>
The reason it is a bit more complicated is that it allows you to make new names (or something) - which is totally not required (not my class).
-
I'm no expert at this sort of thing... but php.net has plenty of these scripts...
<?php $filename = "whatever.xxx"; $myFile = "/absolute/path/to/whatever.xxx"; $mm_type="application/octet-stream"; header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); header("Content-Type: " . $mm_type); header("Content-Length: " .(string)(filesize($myFile)) ); header('Content-Disposition: attachment; filename="'.$filename.'"'); header("Content-Transfer-Encoding: binary\n"); readfile($myFile); ?>
-
Try this:
<?php class Timing { private $store; public function __construct($name = 'default') { $this->store[$name]['start'] = explode(' ', microtime()); } public function stop($name = 'default') { $this->store[$name]['stop'] = explode(' ', microtime()); } public function getTime($name = 'default') { if(!isset($this->store[$name]['stop'])) { $this->stop($name); } $seconds = $this->store[$name]['stop'][1] - $this->store[$name]['start'][1]; $micros = $this->store[$name]['stop'][0] - $this->store[$name]['start'][0]; return $seconds + $micros; } } ?>
Usage:
<?php $timer = new Timer(); ## Whatever..... echo $timer->getTime(); ?>
You need to include the class, and then initialise the timer in your bootstrap/setup file.
-
You sure? You shouldn't wee that if the headers are correctly set, do you have a link?
-
You need to output the correct headers to the browser telling it that your content is a file not a page. Try Googling the issue and I'm sure you will find a solution for your file types.
-
http://nz.php.net/manual/en/function.imagecopyresampled.php
This is a far better function - I never use imageCopyRezised for just this reason. Resampling does take more memory though...
-
You need to use the full data in your functions - i.e. pull a bit more from your database. E.g.
<?php $time = '14:26:13'; $date = '2008-09-01'; $timezone = 'GMT'; $new_time = strtotime($date.' '.$time.' '.$timezone); ?>
Or better, you should store date and time together (datetime) and then pull them from the database using "SELECT UNIX_TIMESTAMP(`datetime_field`) WHERE ...."
-
Means that you haven't defined the function bottom. You need to include your functions file.
-
There are lots of php classes to do this, from Google you could try this one: http://www.phpclasses.org/browse/package/3797.html - returns the data as a php array.
Enjoy
-
Really odd: I get
The largest number in the file is: 1010
-
I think you can do this with JS helpers (try Mootools extensions), but the more common way to do this is with a Flash program. I'm sure the one I used once was called fupload, but I can't find it now...
-
forget php (although it is possible and I have written classes for this before) and look to perl.
Search CPAN for Mechanize and tokeparser. They are the packages that you need to get going. If you are a m$ user you will likely need cygwin or something to run perl.
Please don't build a spambot with these tools...
-
<?php mysql_query("INSERT INTO users (userName, userUser, userPass, UserID, userEmail) VALUES ('".$regOptions['username']."', '".$regOptions['username']."', '".$regOptions['password']."', '".$memberID."', '".$regOptions['email']."')"); ?>
This still does not data sanitisation - make sure you check for the usual culprits like sql injection...
Cheers,
Paul
-
Dear god that's a lot of code... I would have to assume that the <form> elements are in your header / footer include files - although I don't have time to read 800 lines of code looking for them... You could also be using a framework with the helpers included for you - again, I don't know.
Hopefully my previous post will have given you the most basic example possible and you can go from there.
Good luck!
-
You are missing quotes around the strings as previously mentioned by PFMaBiSmAd - I missed that before, sorry - so used to seeing " SET `x` = ?, `y` = ? "etc - didn't even cross my mind!
-
Very odd, I tested it using an array and it worked fine. You may be on a different PHP version to me, so I have made two changes to the core code - give them a go.
<?php print "The largest number in the file is:<br /><br />"; $bfile = array( 'none | 1', 'none | 2', 'none | 13', 'none | 4', 'none | 5', 'none | 6', 'none | 1010', 'none | 950', 'none | 93', 'none | 8', 'none | 11', 'none | 12', 'none | 3', 'none | 14', 'none | 16' ); foreach($bfile as $key => $value) { $tmp = explode('|', $value); $vals[] = trim($tmp[1]); } rsort($vals, SORT_NUMERIC); echo $vals[0].'<br />';
-
Try this:
<?php foreach($bfile as $key => $value) { $tmp = explode('|', $value); $vals[] = $tmp[1]; } rsort($vals); echo $vals[0].'<br />'; ?>
-
Quote error...
<?php $query = "UPDATE items SET color='#FF7200', taken='$username' WHERE id = '{$_GET['take']}'"; ?>
-
Might want to escape the slashes before inserting entries into a database like that. either use sprintf format for the query or use addslashes() on each of the variables in your query. Never trust user content!!
-
I'm not an expert on session issues, but have you tried renaming the id variable to say user_id as your shared hosting may have a 'helpful' custom extension that uses / reserves the $_SESSION['id'] variable. Worth a go?
-
In order to submit any user input (e.g. textarea / select / input) you need to wrap your fields in a form. Below is a basic example which should allow you to see what is going on - the page simple submits to itself for now, but should get you going:
<?php $options = array( 1 => 'Bad', 2 => 'Poor', 3 => 'Average', 4 => 'Good', 5 => 'Excellent' ); if(isset($_POST['rateme'])) { echo 'You clicked save! and chose '.$options[$_POST['rating']].'<br /><br />'; echo 'The posted data looks like this:</br />'; echo '<pre>'; print_r($_POST); echo '</pre>'; } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <select name="rating"> <?php foreach($options as $key => $value) { echo '<option value="'.$key.'"'; if((isset($_POST['rating']) AND $_POST['rating'] == $key) OR (!isset($_POST['rating']) AND $key == 3)) { echo ' selected="selected"'; } echo '>'.$value.'</option>'; } ?> </select> <input type="submit" name="rateme" value="Save" /> </form>
-
Not heard of a method, they do however offer SDKs all major OS, so you could always use exec(); I guess.
I suppose contacting them would be best... https://www.digimarc.com/resources/contact.asp
[SOLVED] Zend FW 1.5 ErrorController Issues
in Frameworks
Posted
Found a work around online (credit to Daniel Cousineau). Apparently the ZF does not allow for multiple error controllers by default - God knows why not - it is very useful to be able to handle errors differently for different modules...
and then in the bootstrap just register an extra plugin:
Hope this helps others...