|
Little Brittle posted:I can't figure out how to get wrappers working, so I'll just use CURL. Thanks for the tip. I don't think you can do that with XPath alone. Try pulling the node via XPath, then reading the attribute from the results. Example: php:<? $nodes = $xpath->query('//REF'); foreach ($nodes as $n) { echo $n->getAttribute('HREF'); } ?>
|
# ? Jul 4, 2008 21:38 |
|
|
# ? May 16, 2024 18:12 |
|
the xpath is /ref/@href. Edit: No it isn't - oops. tef fucked around with this message at 08:26 on Jul 5, 2008 |
# ? Jul 5, 2008 01:14 |
|
Little Brittle posted:I can't figure out how to get wrappers working, so I'll just use CURL. Thanks for the tip. You need the // to search all nodes for the REF tag otherwise the query is /ASX/ENTRY/REF/@HREF In most engines the tag/attribute name matching can be case sensitive, so check first. waffle iron fucked around with this message at 04:34 on Jul 5, 2008 |
# ? Jul 5, 2008 04:32 |
|
Finally got it, thanks for the help everyone. Another question that has been boggling my mind: How can I grab a page's content via curl that requires the URL to be urldecoded? A site I'm working with requires spaces in the URI, and 301 redirects if it has any '%20' characters. That redirect causes curl to error and not grab the page. My host doesn't allow CURLOPT_FOLLOWLOCATION, and I've read that enabling it can be a security concern. Here's an example: The URL should look like this: code:
code:
|
# ? Jul 5, 2008 06:24 |
|
Little Brittle posted:Is there any way to pass curl an urldecoded URL? urldecode() Is this what you're looking for or does PHP's curl function crap out when you use URIs with spaces? Either way, URIs with spaces breaks standards. You should be requesting the document with an encoded URI, then have the target site decode it at that end. Zorilla fucked around with this message at 10:40 on Jul 5, 2008 |
# ? Jul 5, 2008 10:34 |
|
The problem is, the site redirects urlencoded requests and curl can't follow the redirect. If I pass an urldecoded string to curl, it automatically tries to grab the urlencoded page. Unless there is some little-known parameter that makes curl ignore urldecoded URLs, I don't see a solution to grab a page with spaces in the URI when the host site requires it.
|
# ? Jul 5, 2008 19:48 |
|
Little Brittle posted:The problem is, the site redirects urlencoded requests and curl can't follow the redirect. If I pass an urldecoded string to curl, it automatically tries to grab the urlencoded page. Unless there is some little-known parameter that makes curl ignore urldecoded URLs, I don't see a solution to grab a page with spaces in the URI when the host site requires it. That doesn't make much sense. Like Zorilla said, it violates the standards. What happens when you put the URL with spaces in a browser's address bar? How about when you replace the spaces with + instead of %20? Edit: By the way, you can tell cURL to follow redirects by setting the CURLOPT_FOLLOWLOCATION option to true. DaTroof fucked around with this message at 20:09 on Jul 5, 2008 |
# ? Jul 5, 2008 20:00 |
|
DaTroof posted:That doesn't make much sense. Like Zorilla said, it violates the standards. What happens when you put the URL with spaces in a browser's address bar? How about when you replace the spaces with + instead of %20? I know it violates standards, but that's how they roll. When you put the URL with spaces in the address bar, the spaces are not converted. If you put the address in with %20, the page is redirected and they are converted to spaces. I know you can follow redirects with curl, but my host disallows CURLOPT_FOLLOWLOCATION for security reasons. I think you have to disable open_basedir in order to enable it, and I've read that opens up a whole host of problems.
|
# ? Jul 5, 2008 21:25 |
|
Is that URL going to an actual path, such as photos/my cool album/100.html, or is it rewriting to something like index.php?get1=photos&get2=my cool album&get3=100 If it's the latter, it makes sense that it's redirecting on you since it can't find any entries literally named "my%20cool%20album" in the database and is probably doing something like taking you back to the front page because of it. If this is what it's doing, you could probably substitute spaces with + since that's what web browsers and PHP expect (and does automatically for things like multiple search keywords in forms). Zorilla fucked around with this message at 22:20 on Jul 5, 2008 |
# ? Jul 5, 2008 22:16 |
|
I have Visual Studio 2008 through my school and I am wondering if you'd recommend them as a PHP debugger? I don't think that PHP comes standard in VS2008 so which add on would you recommend to allow PHP functionality?
|
# ? Jul 5, 2008 22:23 |
|
Zorilla posted:Is that URL going to an actual path, such as photos/my cool album/100.html, or is it rewriting to something like index.php?get1=photos&get2=my cool album&get3=100 It's the actual path where the content is located. Properly encoded URLs are redirected to the standard-violating path.
|
# ? Jul 5, 2008 22:59 |
|
cannibustacap posted:I have Visual Studio 2008 through my school and I am wondering if you'd recommend them as a PHP debugger? I don't think that PHP comes standard in VS2008 so which add on would you recommend to allow PHP functionality? I believe there is a commercial PHP debugger for VS, but you are probably better off just using a good text editor. If you need a real debugger that you can step through code with, try Zend Studio, Eclipse, Komodo, or (preferably )Vim.
|
# ? Jul 5, 2008 23:00 |
|
Anveo posted:I believe there is a commercial PHP debugger for VS, but you are probably better off just using a good text editor. If you need a real debugger that you can step through code with, try Zend Studio, Eclipse, Komodo, or (preferably )Vim. I was looking around and I think I may just use the netbeans + xdebug option http://www.netbeans.org/kb/61/php/installing-and-configuring-required-software.html What do you think?
|
# ? Jul 5, 2008 23:07 |
|
Little Brittle posted:It's the actual path where the content is located. Properly encoded URLs are redirected to the standard-violating path. That's what doesn't make sense to me. The browser should encode the URL before it gets sent. If the browser requests a URL with illegal characters, the server should respond with a bad request error. If it requests a URL with encoding, the server should unencode it before it tries to resolve it to a local file path, so you shouldn't need the redirect in the first place.
|
# ? Jul 5, 2008 23:42 |
|
Yeah, this is starting to sound like a fundamental server problem to me. Even with absolutely no dynamic code, %20 should be interpreted as a space by the web server for any case in which directories have spaces in them, not redirecting. I have to wonder how you're even able to access the page through an ordinary web browser (as opposed to curl) since they encode illegal characters on the fly once you hit "Go" on the URL bar. If you're comfortable with it, would you like to paste your .htaccess file to see if it sheds any light on this problem? Zorilla fucked around with this message at 00:27 on Jul 6, 2008 |
# ? Jul 6, 2008 00:19 |
|
This is a remote server I'm grabbing info from, so I don't have the htaccess file available. I managed to grab the page with file_get_contents() as opposed to curl, so that will work for now. I have no idea what their server config is, but I've never seen anything like that before either.
|
# ? Jul 6, 2008 08:24 |
|
A while ago when I started doing PHP/MySQL I downloaded this great software bundle called phpdev (http://www.firepages.com.au/yak2.htm/down1). It basically gives you everything you need to locally develop PHP/MySQL web apps: a local apache server w/PHP modules installed, MySQL, and phpmyadmin all set up and ready to go. It hasn't been updated recently and I'd like to use the MySQL/phpmyadmin setup as a database for another server-side scripting framework but I want to use the latest version of MySQL and phpmyadmin. Downloading the latest version of phpmyadmin is easy - I just get the php files and put them in the appropriate directory, but I don't know what to do about mysql. Has anyone here ever used phpdev and can anyone perhaps let me know how I could download/setup the latest version of MySQL to work with this bundle? I'd appreciate it. Thanks.
|
# ? Jul 7, 2008 08:55 |
Rabbi Dan posted:It hasn't been updated recently and I'd like to use the MySQL/phpmyadmin setup as a database for another server-side scripting framework but I want to use the latest version of MySQL and phpmyadmin. Check out XAMPP, it is updated quite frequently.
|
|
# ? Jul 7, 2008 09:00 |
|
I'm using Dreamweaver CS3 to create some PHP pages, and 100% of the PHP code on my site is generated automatically through Dreamweaver. After using it a while, I can spot errors and fix them, but I haven't really created anything myself. So: Can I call for a specific data entry in a specific spot? Let's say in Spot #1 I want Entry x. In Spot #2 I want Entry x-1. In Spot #3, I want Entry x-2. I know that sounds like a "repeating region", but I want to change the information displayed based on the spot. (I've got a newsstory database. Spot #1 is displayed with photo/headline/byline/summary, for example. Spot #2 is just photo/headline, etc.) Dreamweaver's "repeating region" displays all the information the same way. Are there any resources/tutorials for this? I'd Google it, but it took me 20 minutes just to figure out how to convey my idea without any real hands-on PHP experience, and I'm still not sure how clear it is.
|
# ? Jul 8, 2008 22:21 |
|
You know I'm as willing to stick up for PHP as just about anyone when the going gets tough but I've just come across something that is such complete idiocy that I can't even begin to fathom why whoever wrote it is even allowed to continue existing. I think we all accepted a long time ago that PHPs core functions were a bit loopy and zany, like a very inconsistent clown. For instance today I became annoyed once more in PHPs assumption that I never want to preserve keys in my arrays. Excuse me sir, you want to preserve keys in array_reverse()? Well you better flag it because obviously it sense to not preserve them by default! Then today after crafting quite a handsome depthSort() function that will sort an array of arrays based on a consistent internal key and testing it using associative and non-associative keys such as: php:<? $thisarr = array ('Ben' => array ('Happy' => 12, 'Sad' => 20), 'Rob' => array ('Happy' => 10, 'Sad' => 22), 'Mike' => array ('Happy' => 5, 'Sad' => 100)); $thisarr = depthSort($thisarr, "Happy"); print_r($thisarr); ?> Array ( [6] => Array ( [Total] => 4 [Correct] => 2 ) [11] => Array ( [Total] => 4 [Correct] => 2 ) [10] => Array ( [Total] => 4 [Correct] => 2 ) [7] => Array ( [Total] => 4 [Correct] => 2 ) [3] => Array ( [Total] => 3 [Correct] => 2 ) [8] => Array ( [Total] => 4 [Correct] => 1 ) [1] => Array ( [Total] => 4 [Correct] => 0 ) [9] => Array ( [Total] => 3 [Correct] => 2 ) [2] => Array ( [Total] => 4 [Correct] => 3 ) [5] => Array ( [Total] => 3 [Correct] => 1 ) [4] => Array ( [Total] => 3 [Correct] => 2 ) ) After having it not work for a while and trying to figure out what the problem is, I head over to php.net to take a look at some of the internal functions that depthSort() uses to see if I can find the problem. Low and behold: array_multisort() can be used to sort several arrays at once, or a multi-dimensional array by one or more dimensions. Associative (string) keys will be maintained, but numeric keys will be re-indexed. I just can't fathom why anyone thought this would be a good idea? Why is it that they've decided that numeric keys are completely useless and no would ever use them associatively? I mean there has to be a reason doesn't there? Please can someone explain to me why someone lacked such basic sense as to automatically re-index an array thats being sorted by an integer based key? Gah sometimes PHP.
|
# ? Jul 9, 2008 15:28 |
|
Evil Angry Cat posted:I just can't fathom why anyone thought this would be a good idea? Why is it that they've decided that numeric keys are completely useless and no would ever use them associatively? I mean there has to be a reason doesn't there? Please can someone explain to me why someone lacked such basic sense as to automatically re-index an array thats being sorted by an integer based key? Gah sometimes PHP. I think I see what you're getting at. Unfortunately things don't work out for you in this instance, but overall it makes more sense to do what they're doing. The reason is that all PHP arrays are associative, but 'unkeyed' arrays typically rely on keyed values to determine order. It wouldn't make sense for me to create $a=Array('Z','Y','X') and have $a[0] return the same value before and after the sort. I wasn't aware before that there are PHP functions which will step through a list in the order it's stored, even if some of the keys are integers that are out of order. This is good to know. php:<? $a=Array(1=>'A', 0=>'B');//Same as $a=Array('1'=>'A', '0'=>'B'); echo $a[0];//B foreach($a as $i)echo $i;//AB for($i=0;$i<count($a);$i++)echo $a[$i];//BA ?> functional fucked around with this message at 16:10 on Jul 9, 2008 |
# ? Jul 9, 2008 16:06 |
|
functional posted:The reason is that all PHP arrays are associative, but 'unkeyed' arrays typically rely on keyed values to determine order. It wouldn't make sense for me to create $a=Array('Z','Y','X') and have $a[0] return the same value before and after the sort. Good point well made. If only they'd give me the option though like they do with all of their other barmy array functions I'd be happy.
|
# ? Jul 9, 2008 20:28 |
|
Evil Angry Cat posted:If only they'd give me the option though like they do with all of their other barmy array functions I'd be happy. Yep, you're right. There ought to be an option for what you want to do. I would submit a feature request. It shouldn't be a difficult change to implement. (Presuming asort() is insufficient for your application.) functional fucked around with this message at 21:20 on Jul 9, 2008 |
# ? Jul 9, 2008 21:13 |
|
In PHP using the MVC method, I see a lot of people criticize for using foreach() inside a view. I understand why this might be bad, as it's always best to keep the PHP and HTML as seperated as possible, but I don't understand why this situation is so unacceptable. If I want to build a table of information on my page based on database results, I'll have to build the table's rows HTML inside the controller, and then echo that in the view, or pass the data and loop inside the view. In either of these instances, I'm mixing code, but as far as I can tell it's unavoidable. Is there a better way that I'm not seeing?
|
# ? Jul 9, 2008 22:25 |
Stephen posted:In PHP using the MVC method, I see a lot of people criticize for using foreach() inside a view. No, you have to. I can't imagine anybody criticizing that. If you're a smarty pants you use a {foreach from=$myArray item=foo}
|
|
# ? Jul 9, 2008 22:34 |
|
I have a web form and want the action page to be self.php with an anchor "anc"code:
are getting 404 errors because the url is resolving to self.php%23com. The character code for # is "%23". Is there any way to make this work both ways? Is there a redirect I can do in my .htacesss to make this work?
|
# ? Jul 10, 2008 00:51 |
|
Yeah, foreach is basically the control flow construct for templates. It needs minimal logic and produces the desired behaviour. If you wanted to put foreach loops out of your templates, you'd probably have to generate all the HTML that requires looping in the controllers and then pass that off to the views ...
|
# ? Jul 10, 2008 01:01 |
|
Bonus posted:Yeah, foreach is basically the control flow construct for templates. It needs minimal logic and produces the desired behaviour. If you wanted to put foreach loops out of your templates, you'd probably have to generate all the HTML that requires looping in the controllers and then pass that off to the views ... the first and worst sin of home-grown template engines is usually that they suck at iteration, which usually means they suck loving period. either you're using a foreach() in your templates, or you have some equivalent to a foreach() method in your template engine, or your template engine loving sucks. even trivial web sites usually need some way to loop through a collection, for chrissake
|
# ? Jul 10, 2008 02:43 |
|
PHP's foreach is a mess. You need to be really careful with it because of how it performs implicit copies and may screw around with references in unexpected ways. Because PHP has no lexical scope, foreach also does not clean up after itself properly as it does in other languages. The effects differ depending what version of PHP you are using. I think a for loop is much safer and predictable.
|
# ? Jul 10, 2008 03:24 |
|
genericadmin posted:PHP's foreach is a mess. You need to be really careful with it because of how it performs implicit copies and may screw around with references in unexpected ways. Because PHP has no lexical scope, foreach also does not clean up after itself properly as it does in other languages. The biggest issue is that referencing switched from PHP4 to PHP5, at least with regard to objects. In PHP5 objects are always referenced when using '=', arrays are referenced using '=&' In PHP5 a '=&' on an object makes a 'hard-link', Example: $a = new ABC(); $b =& $a; unset($b); Edit: I think this might actually be a clone (shallow copy) but it's deprecated in PHP5 regardless. That will actually unset $a because it's a 'hard-link', just using a normal reference or copy would leave just $b unset. With regards to a foreach, you can specify to do foreach($array as &$value) which allows you to not copy the array but do it b y reference instead. (the & in front of the $value). Also be aware that foreach will move the array pointer also (but calling foreach resets it back to the start). MrEnigma fucked around with this message at 06:37 on Jul 10, 2008 |
# ? Jul 10, 2008 06:25 |
Will an if statement try the rest of the conditions after the first one fails?
|
|
# ? Jul 10, 2008 10:41 |
|
fletcher posted:Will an if statement try the rest of the conditions after the first one fails? No, it'll only go as far as it needs (from left-to-right). That is: php:<? if (a() || b()) # b() won't be called if a() returns true { ... if (a() && b()) # b() won't be called if a() returns false { ... ?>
|
# ? Jul 10, 2008 10:54 |
|
I apologize if this has already been asked. I'm working on a small e-commerce site for a friend. I'm building a very simple admin interface to add items to the database (MySQL). She wants to be able to upload a description, title, and image. 1) She's a graphic designer so she suggested manually resizing the images herself and uploading two images (full-sized and thumbnail) at once. Would there be a way to let her only give the larger image and have a script automatically resize it to the appropriate sized thumbnail without quality loss? 2) Since I've never worked with images/BLOBs before, is there anything I need to be aware of? Is it possible to do mysql injection or other bad things with image data. I saw an online tutorial that used addslashes() on the image data; I used mysql_real_escape_string on my previous site so I'd like a goon opinion or two.
|
# ? Jul 10, 2008 14:01 |
|
chocojosh posted:I apologize if this has already been asked. 1) http://au.php.net/gd 2) Don't store images in the db. Instead, write an upload script that stores the file on the server (an upload folder or something), rename the stored file to a uniqid().extension so you don't have to worry about same-name photos, and store it in the database as something like imageID | physical_name | alt_text?orsomething (assuming the image is only used for a single product)
|
# ? Jul 10, 2008 14:38 |
|
I was actually hoping to store the images in the database although I've read that it's a more common approach to store them in the file system. Any reasons why I shouldn't store them in the DB?
|
# ? Jul 10, 2008 17:00 |
|
Yeah.
|
# ? Jul 10, 2008 17:10 |
|
So I'm trying to implement Dijkstra's algorithm for a side project I'm working on but I'm having difficulty grasping how the whole thing works... I've setup a map where each location a player can be go to is identified as a sector. Each sector knows whether it connects to any of the sectors to the north, east, south, or west of it. In MySQL, the table for sectors looks like this: table: sectors sector_id | north | east | south | west If the current sector connects with another (eg. north) then it would have the sector_id in that field. Otherwise the value of 0 would be in the field. Would the connecting sectors be the vertices? To illustrate it, the map array might look something like this: code:
Acer Pilot fucked around with this message at 00:34 on Jul 11, 2008 |
# ? Jul 11, 2008 00:31 |
|
code:
If I move either of the prepares right above the execute() line, it works perfectly. Can anyone tell me what the issue is, or am I just retarded?
|
# ? Jul 11, 2008 19:40 |
|
Why in the world did you put the prepare statement into a wrapper? That seems ... wasteful? What happens when you just run the prepare without the wrapper?
|
# ? Jul 11, 2008 20:16 |
|
|
# ? May 16, 2024 18:12 |
|
SuckerPunched posted:Why in the world did you put the prepare statement into a wrapper? That seems ... wasteful? What happens when you just run the prepare without the wrapper? I'm really just experimenting mostly. This is the first time I've used PDO's. code:
code:
code:
Stephen fucked around with this message at 20:29 on Jul 11, 2008 |
# ? Jul 11, 2008 20:20 |