[PHP] Converting string representation of a directory to multi-dimensional array
Over the weekend, I was tasked with taking a string representation of a directory ('\Interface\Addons\\'), which can vary in length (no set number of depths) to a multi-dimensional array (i.e. array('Interface' => array('Addons' => array('' => )));). We came up with a very ugly hack to do it, but I'm curious if anyone can help us wrap our head around a better solution, without using eval (which we were able to find that solution quickly, but do not want to use eval). Our situation is a little unique in the fact that these files don't actually exist on a filesystem, so it makes it a bit more tough to actually create this array. Thanks for any help you can give in cleaning this up somewhat. Here is the function we currently use: > default: break; } } print_r($array); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Server Stall
If you have cURL installed, you could use Curl to get the file, and manipulate the contents that way. Here is the standard function I use for grabbing a remote page. function doRequest($method, $url, $vars = '', $headers = '0') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, $headers); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); if ($method == 'POST') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); } $data = curl_exec($ch); curl_close($ch); if ($data) { return $data; } else { return curl_error($ch); } } called with doRequest('GET', ''); $vars would be either a string or an array of post variables, and headers either shows or hides headers from the webserver. CURLOPT_TIMEOUT is set to 30, but you can change that to how many seconds you'd like to wait. - Original Message From: Sancar Saran <[EMAIL PROTECTED]> To: php-general@lists.php.net Sent: Monday, February 5, 2007 11:42:56 AM Subject: [PHP] Server Stall Hi, One of my scripts are using wget to get external xml data $fp = popen ("wget -O - '".$dst."' | cat","r"); Some time $dst host responds very slowly. And that time if I open another connection to same server the second request waits to complete wget operation. I'm very noobie about this file operations. Is there any suggestion about this situation ? Regards. Sancar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting string representation of a directory to multi-dimensional array
It will never receive a base name due to the way the data is structured before being passed into the function. I appreciate everyone's input on this. It's been tough for us to develop what we did (since it's such an odd case), and it's good to see other possible methods to do this in a better manor. - Original Message From: Roman Neuhauser <[EMAIL PROTECTED]> To: Jochem Maas <[EMAIL PROTECTED]> Cc: php-general@lists.php.net Sent: Tuesday, February 6, 2007 9:03:35 AM Subject: Re: [PHP] Converting string representation of a directory to multi-dimensional array I had wanted to post something when the thread started, but gave up, because I quickly ran into ambiguities. What should the conversion do when given a basename, e. g. addToList("file.txt", ...)? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP or Bridge (card game)
Having learned Bridge when I was younger, I feel PHP is alot easier to learn as it is "constant" in a way. Depending on cards you are holding, cards your partner is holding, and your oponents bidding, depends how you should bid. Quite a bit of variablity in there. - Original Message From: Kenn Murrah <[EMAIL PROTECTED]> To: pub <[EMAIL PROTECTED]> Cc: PHP General List Sent: Saturday, February 10, 2007 3:57:03 PM Subject: Re: [PHP] PHP or Bridge (card game) pub wrote: > which do you think is harder to learn, PHP or bridge? > Well, PHP *can* be a lot more complicated, but at least it's more or less predictable, and I've RARELY had a bridge partner that played the game predictably and consistently kennM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array issues
If i'm understanding you correctly, you have something like a flat file, and hopefully it is artist[tab]artist[tab] with the title being something like artist1title[tab]artist2title[tab], etc. If so, use explode. $artists = explode("\t", $stringofartists); $songs = explode("\t", $stringoftitles); $i = 0; foreach($artists as $key) { $information[$key] = $songs[$i]; $i++; } I hope this is kind of what you were looking for. [snip] Artist[tab]artist[tab]artist[tab] etc as a entry for "artists" [/snip] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP Documentation in XML
Does anyone know where I could find PHP Documentation in XML or in an SQL dump? I'm trying to write an IRC bot that can retrieve information on php functions, and am realizing this would be the easiest way. Thanks in advance. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable variables and references
I've used variable variables probably 5 times in 2 years. They are great when you need them, but don't usually have a day-to-day use for them. Here is some sample code of the last time I used it. if(isset($$key)) { print($$key); continue; } else { $iquery = "SELECT * FROM `".ROSTER_ITEMSTABLE."` WHERE `item_name` = '".$iname."' AND `member_id` = '".$row['member_id']."'"; $iresult = $wowdb->query($iquery); $idata = $wowdb->fetch_assoc($iresult); $item = new item($idata); $$key = $item->out(); print $$key; } Basically, this is in a for-each loop, that steps through a list of keys for certain dungeons in World of Warcraft. Instead of putting the data into an array, I used variable variables to stick the data into a single variable. The way it works is $key = 'DM'; $$key = $data; The literal translation for $$key is $DM once the code executes. Hope this helps. - Original Message From: Dave Goodchild <[EMAIL PROTECTED]> To: PHP-General Sent: Saturday, March 10, 2007 5:28:57 AM Subject: [PHP] Variable variables and references Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I think it's a great book, I am confused about variable variables and references - not the mechanics, just where you would use them. The subject of variable variables is explained but no examples are given as to why and where you would utilise them. As for references, the examples given with regard to passing and returning by reference in functions is clear, but no real examples are given as to when this would be a preferred approcah - in fact, the authors stress that due to PHP's copy-on-write mechanism, it is not a frequently-used approcah. So my question - are there any 'classic' situations in which either should be used, and where and when do you guys use them in your real-world efforts? -- http://www.web-buddha.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 2 errors I can not understand
I think you have an issue with the line while($d<$s) when it comes to the number 3. $d will NEVER be < $s if $s = 3. I think you want $d<=$s?? Or maybe a switch for the number 3? - Original Message From: Jonathan Kahan <[EMAIL PROTECTED]> To: php Lists Sent: Tuesday, March 13, 2007 4:30:45 PM Subject: [PHP] 2 errors I can not understand Hi all, Please see my output below followed by the code. I have been trying for some to figure out why 1) I can not get a line feed to work in the web page that i am using to display the output as I am not running from the commad line 2) Why my loop is only executing 3 times when i want it to execute 50 Any help would be greatly appreciated. Jonathan The next line is all that displays on the output html page: Output: The number 0 is 0 The number 1 is 0 The number 2 is 1 The number 3 is 1 php script: "tjon2.php" 78L, 447C written -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 2 errors I can not understand
I retract my statement. I think I spoke too quickly. I think I don't fully understand the code (can't pay attention right now for some reason), and I talked too quick. I do think it has to do with the while loop though, as that is where it seems to be dying. - Original Message ---- From: Matt Carlson <[EMAIL PROTECTED]> To: Jonathan Kahan <[EMAIL PROTECTED]>; php Lists Sent: Tuesday, March 13, 2007 5:12:03 PM Subject: Re: [PHP] 2 errors I can not understand I think you have an issue with the line while($d<$s) when it comes to the number 3. $d will NEVER be < $s if $s = 3. I think you want $d<=$s?? Or maybe a switch for the number 3? - Original Message From: Jonathan Kahan <[EMAIL PROTECTED]> To: php Lists Sent: Tuesday, March 13, 2007 4:30:45 PM Subject: [PHP] 2 errors I can not understand Hi all, Please see my output below followed by the code. I have been trying for some to figure out why 1) I can not get a line feed to work in the web page that i am using to display the output as I am not running from the commad line 2) Why my loop is only executing 3 times when i want it to execute 50 Any help would be greatly appreciated. Jonathan The next line is all that displays on the output html page: Output: The number 0 is 0 The number 1 is 0 The number 2 is 1 The number 3 is 1 php script: "tjon2.php" 78L, 447C written -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Integer question
When dealing with large numbers inside of php, I know at the int limit, a variable is recast into float. 1). How do you return the true number of the float when it reaches the upper limits of mysql's bigint (9223372036854775807). 2). How do you handle numbers that large, while maintaining precision. 3). Is there a php equivalent of unsigned? Thanks all -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Integer question
When dealing with large numbers inside of php, I know at the int limit, a variable is recast into float. 1). How do you return the true number of the float when it reaches the upper limits of mysql's bigint (9223372036854775807). 2). How do you handle numbers that large, while maintaining precision. 3). Is there a php equivalent of unsigned? Thanks all -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where is phpm
I don't know how much of it I have left. I know that I hacked it up quite a bit when I created an irc bot with the php reference manual. Unfortunately, there really isn't an easy way to get function information as such from inside of php, without parsing php's website. The phpdoc stuff wasn't very intuitive on how to parse it, and trying to search for "xml php documentation" didn't really help (wy too many results, mostly dealing with how to use xml in php). If you DO find the updated info, I would also love to get a copy, as my hacked up version seems to be quite old. - Original Message From: Ben Roberts <[EMAIL PROTECTED]> To: php-general@lists.php.net Cc: Ben Roberts <[EMAIL PROTECTED]> Sent: Thursday, March 29, 2007 1:49:37 PM Subject: Re: [PHP] Where is phpm Ben Roberts wrote: > > I'm trying to download the phpm command line PHP documentation widget - > all sources I can find point me to http://eide.org/?epc=php but there's > nothing available here. > > Does anyone know where I can find phpm please ? > > Thanks > > Ben > Any takers? Has anyone got a copy of phpm they can send to me instead? Does anybody know anything about phpm. I'm trying to get vim to lookup function references in the PHP manual. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Question on Portfoilo's
So i've been meaning to start a portfolio of some code, so that when I apply for a job, and they want code samples, I have something to show them. Unfortunately, at this time, most of my work is inside of a much larger application, or in code that belongs to my current employer (not a php job, just misc. things i've made). What kind of things do you guys have in your portfolio's/code samples that your provide to a potential employer? What things do you feel I should avoid when putting this kinda of thing together? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 'lang' file editor ...
I am running into the same problem. A very VERY basic thing that I worked on for importing yielded this: preg_match_all('/.*?(?:\$lang([^=]*)=(.*?); *$.*?)+/ms', file_get_contents("localization/enUS.php"), $parsed); It wasn't the best, but it worked 90% of the time. Maybe this can help you on the parsing front. - Original Message From: Jochem Maas <[EMAIL PROTECTED]> To: Jim Lucas <[EMAIL PROTECTED]> Cc: [EMAIL PROTECTED]; [php] PHP General List <[EMAIL PROTECTED]> Sent: Thursday, April 12, 2007 5:11:39 AM Subject: Re: [PHP] 'lang' file editor ... what I'm looking for is something that will make it possible for an end user to merge [the contents] existing language files (that contain the items for the same language) *and* perform translations between languages in a visual/easy way (i.e. without opening a text editor) but end up with lang files that still formatted and commented when I'm done. it's a three step process: 1. 'parse' 2 files: a 'reference' and a 'translation' file 2. display an editing interface for the 2 files (textareas, filtering [e.g. show only untranslated items], sorting, etc) 3. write out a merged/updated file. probably the merging of 2 existing lang files of the same language will require a seperate interface than the translation/comparison of 2 files containing different languages. I have made a half-assed attempt to do this some years ago and it worked ok but wasn't quite the level of sophistication I desired - If no one has anything like this lying around then I guess it's time for me to hack up a new thingummy, using var_export()/print_r() [and running the code to merge, etc] won't cut it (I've been down that road already) so probably I'm looking at using either the tokenizer (although how exactly is something I'd have to look into) or a combination of preg_match()/preg_replace() (which is something I am confident I can now do to the required level - when I tried before my regexp skills sucked too much). I'm quite sure I make it work, but I'd be surprised if no-one has gone before me - there must be tons of projects out there with the same kind of language file structure ... maybe I should consider moving my 'shit' into gettext format. Jim Lucas wrote: > Richard Lynch wrote: >> Seems to me you'd be better off just running the PHP code and dumping >> the arrays out with var_dump or print_r "like" function to generate >> your new language files... >> >> Otherwise, you're writing a fairly big chunk of the PHP parser, which >> is already in PHP, so you re-invent the wheel... >> >> On Wed, April 11, 2007 9:07 pm, Jochem Maas wrote: >>> anyone know of a decent script (or something I can rip out of an >>> existing OS tool) >>> that is capable of comparing, editing and saving 'old skool' lang >>> files - you know >>> the ones which define tons of array elements e.g.: >>> >>> $Lang['foo'] = 'bar'; >>> >>> I'm looking for something that can handle quotes properly and 'weird' >>> array keys >>> (that include constants, for instance) as well as sprintf markers in >>> the 'translation' >>> text (e.g. "my %s hurts") and if at all possible the abiltiy to >>> recognise and not f'up >>> stuff like: >>> >>> $Lang['foo'] = 'my '.$Lang['bar'].' really hurts'; >>> >>> and I'd prefer it to be able to keep file formatting, item ordering >>> and comments >>> as they were when saving back into the file. >>> >>> I can't find anything really useful - the firefox 'php lang file' >>> editor plugin, is, >>> for instance, not up to the job. >>> >>> tar, >>> Jochem >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> >> > From what he said, I read that he want to rip the contents out of the > file, not actually parse it. > > for example, if he parsed this out: > $Lang['foo'] = 'my '.$Lang['bar'].' really hurts'; > > You would get the completed string, not a line that has the variable > call in it. > > Maybe I took it wrong, but that is what I thought he wanted. > > a reader, not a parser. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] should I be looking to eliminate all notices?
I really have to agree here. I have gone through a mature open source project over the last month or so, and removed EVERY notice. It honestly took all of about 2 hours to actually fix the notices. It really isn't hard to eliminate them, and if you are coding something the may be released, you don't know how the end-user will have their error_reporting. I think it's fairly "good practice" to eliminate them. - Original Message From: Edward Vermillion <[EMAIL PROTECTED]> To: Ross <[EMAIL PROTECTED]> Cc: php-general@lists.php.net Sent: Saturday, April 21, 2007 7:17:35 AM Subject: Re: [PHP] should I be looking to eliminate all notices? On Apr 21, 2007, at 4:01 AM, Ross wrote: > A quick one this morning. > > When coding should I be trying to code so there are no notices or > is it ok > to turn them off. > If you don't mind writing code that contains errors, notices are errors. Not serious, but it's not that hard to write code in php that doesn't produce errors. Unless > I don't really want to do a isset check for every index I have. your lazy about your code. Sorry if it sounds harsh, but if you don't want to even check this minor thing then you probably shouldn't be writing code that's going to see the light of day*. Read up on web security. Start here... http://phpsec.org/ I'm betting that if you don't care about checking for set indexes then you're not checking a lot of things that really need to be checked. Ed * Code to bee used on a box connected to the internet. If your just writing some script that you use on your local machine then what you do with notices is your business. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Find file version
I've been recently toying with the idea of creating a php script to emulate the function of File Hippo's program checker (checks certain programs for their version, and then uploads to file hippo to compare with what it is released to show a list of available updates. I've hit a brick wall though. I know binary files have version information available, but can't find anything for php to read this. Has anyone run across something like this in the past? Anyone have any hints of where to go to start reading this info? Thanks Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Find file version
Ya, I'm thinking it will be all exe's. I found microsoft's "Filever" program, but I can't get exec working properly (well, I can't get the results properly). I'm gonna keep searching, and hope I find how it determines file info. - Original Message From: Richard Lynch <[EMAIL PROTECTED]> To: Matt Carlson <[EMAIL PROTECTED]> Cc: php-general@lists.php.net Sent: Friday, July 27, 2007 12:52:08 AM Subject: Re: [PHP] Find file version On Wed, July 25, 2007 12:26 am, Matt Carlson wrote: > I've been recently toying with the idea of creating a php script to > emulate the function of File Hippo's program checker (checks certain > programs for their version, and then uploads to file hippo to compare > with what it is released to show a list of available updates. > > I've hit a brick wall though. I know binary files have version > information available, but can't find anything for php to read this. > > Has anyone run across something like this in the past? Anyone have > any hints of where to go to start reading this info? I don't think there is any magical incantation that works for all binary files... They all store their version info in whatever portion of the file they felt like it... Unless you mean .exe files specifically, in which case it's probably always in the same place in those... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Highjack?
With register_globals on, the globals super array ($_POST, $_GET, $_REQUEST) are automatically populated into variables. With that in mind www.example.com/index.php?path=remoteexplot.com/ would then yield include('remoteexplit.com/foo'); thus including ANY code they wish. - Original Message From: bruce <[EMAIL PROTECTED]> To: Eric Butera <[EMAIL PROTECTED]>; tedd <[EMAIL PROTECTED]> Cc: PHP General List Sent: Monday, November 13, 2006 11:55:13 AM Subject: RE: [PHP] Highjack? eric... you say how embarrasing regaring the $path.'foo' i'm curious, why/how is this simple piece of code exploitable. assuming $path is not something that comes via the url vars (GET/POST/REQUEST) it shouldn't be able to be touched by external/client processes... similarly, the 'foo' would be static, and couldn't be munged... thoughts/explanations... thanks -Original Message- From: Eric Butera [mailto:[EMAIL PROTECTED] Sent: Monday, November 13, 2006 9:39 AM To: tedd Cc: PHP General List Subject: Re: [PHP] Highjack? On 11/13/06, tedd <[EMAIL PROTECTED]> wrote: > Hi gang: > > While this is not an obvious php question, it does deal with security > which is a concern. > > Just this morning had a couple of my sites "highjacked". What I found > was someone had replaced my root level index.php with their own > index.php. You can see the result at: > > http://xn--u2g.com/index1.php > > It was not a terrible loss nor inconvenience, but I wonder how they > did it. Any ideas how this was done and suggestions as to how to > prevent this from happening again? > > Thanks, > > tedd > > -- > --- > http://sperling.com http://ancientstones.com http://earthstones.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Tedd, I've seen this happen before when someone was able to do a remote code execution exploit on an old version of a very popular open source shopping cart project. I'd say the first thing would be to try and find any include/require statements that are exploitable. In the case I was dealing with, it was a problem with register_globals on and an include that looked a bit like this include($path .'script.php');. How embarrassing. If you have access to your server logs look for urls such as http://example.com/exploited.php?action=http://evil.example.com/inject.txt. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wath�s wrong?
I think that one of the issues is that when you assign a variable using "" instead of '', it will auto-replace your variable names inline. I don't know, but I think you should be escaping the $ before the <. --- Jo�o C�ndido de Souza Neto <[EMAIL PROTECTED]> wrote: > Hi everyone. > > I have a var that gets the follow string: > > $var="R$ color=\"".GE_COR_VALOR."\">".number_format($con->result['preco_v'],2,",",".").""; > > When a print it i receive the follow result: > > R$ 150,00 > > Someone knows wath�s happening here? > > Thanks. > > -- > Jo�o C�ndido de Souza Neto > Curitiba Online > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php