Re: [PHP] help with \n\r in strings
Angelo Zanetti wrote: So is there a way to test for \r\n? or what else can I use to delimit these two values (last column of row and first column of next row)? Since it's coming from a file, you might as well just read it with file(), which will split each line into an array automatically. If it's a CSV file, then fgetcsv() helps you out even more. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help
Those patterns aren't anchored to the ends of the string, so as long as the string contains one matching character, the succeeds. ^ anchors the pattern to the beginning, \z to the end, so you want: /^[A-Za-z]+\z/ Or test the opposite case to see if it fails: /[^A-Za-z]/ Arpad Chris Boget wrote: echo 'Is String: [' . ( is_string( 'a1b2c3' ) && preg_match( '/[A-Za-z]+/', 'a1b2c3' )) . ']'; echo 'Is Numeric: [' . ( is_numeric( 'a1b2c3' ) && preg_match( '/[0-9]+/', 'a1b2c3' )) . ']'; echo 'Is String: [' . ( is_string( 'abcdef' ) && preg_match( '/[A-Za-z]+/', 'abcdef' )) . ']'; echo 'Is Numeric: [' . ( is_numeric( '123456' ) && preg_match( '/[0-9]+/', '123456' )) . ']'; ?> Why is the first "Is String" check returning true/showing 1? preg_match should fail because 'a1b2c3' contains numbers and, as such, doesn't match the pattern... What am I doing wrong? thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help
Note that $ allows a trailing newline, but \z doesn't. Arpad Stut wrote: Chris Boget wrote: echo 'Is String: [' . ( is_string( 'a1b2c3' ) && preg_match( '/[A-Za-z]+/', 'a1b2c3' )) . ']'; echo 'Is Numeric: [' . ( is_numeric( 'a1b2c3' ) && preg_match( '/[0-9]+/', 'a1b2c3' )) . ']'; echo 'Is String: [' . ( is_string( 'abcdef' ) && preg_match( '/[A-Za-z]+/', 'abcdef' )) . ']'; echo 'Is Numeric: [' . ( is_numeric( '123456' ) && preg_match( '/[0-9]+/', '123456' )) . ']'; ?> Why is the first "Is String" check returning true/showing 1? preg_match should fail because 'a1b2c3' contains numbers and, as such, doesn't match the pattern... It does match the pattern. The expression says "1 or more A-Za-z in sequence". If you want to check against the whole string you need to add the start and end markers... preg_match( '/^[A-Za-z]+$/', 'a1b2c3' )) Look at the manual page for preg_match and read up on the third parameter. Use it to see what is matching the expression. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Normalized Numbers
Have you checked out the PEAR Validate packages? http://pear.php.net/package/Validate_ISPN in particular might help you along ;) And BTW, most servers are set up to display php files renamed to .phps with syntax highlighting, so give that a try instead of .php.txt next time. Regards, Arpad Brian P. Giroux wrote: I am just learning PHP and as a practical exercise I've been working on a set of functions to process and manipulate what I call "normalized number" (ISBNs, EANs, UPCs, etc...) My ultimate goal is to create a normnum class and child classes for the different types of numbers. Because of my line of work, I am mostly interested in ISBN-10s, ISBN-13s, EANs and UPCs, but it can also be expanded to credit card numbers, Canadian Social Insurance Numbers, and many more. So far I have functions to validate ISBN-10s and EANs although I've run into a bit of a wall with the digit_sum function as explained in the B: section of that functions header comments. If anyone can help me out with that or provide any other advice about the rest of it, I'd be grateful. The file can be found at http://www.senecal.ca/normnums.php.txt Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match problem
Martin Alterisio wrote: Double slash to prevent PHP interpreting the slashes. Also using single quotes would be a good idea: if (preg_match('/[\\w\\x2F]{6,}/',$a)) Just switching to single quotes would do the trick - you don't need to escape anything but single quotes, and backslashes if they are the last character. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert date to reversed date
$filename = implode(array_reverse(explode('/', $value))); Arpad Reinhart Viane wrote: Is this a good way to convert 01/02/2007 to 20070201 $value='01/02/2007'; list($day, $month, $year) = split('[/.-]', $value); $filename=$year.''.$month.''.$day; It does work but i would like to verify if there are no better, more logical ways to do this. Thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OT - Regular Expression
Roman Neuhauser wrote: This shouldn't do too much backtracking, try it out: "*8*" => /^(?:\d*8\d*){4}$/ The {4} in there repeats the subpattern 4 times, rather than limiting it to 4 characters. I really can't think of an elegant to do what you ask with regex - why limit yourself to regex anyway? It would be far simpler to just convert * to .* and check the length separately with strlen(), plus if you check the length first then you don't need regex at all if it fails. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to get original post data?
$post = file_get_contents('php://input'); Or for older versions of PHP, just use $HTTP_RAW_POST_DATA. Arpad Nicholas Yim wrote: > Hello EveryOne, > > like parse the soap request body > > not through $_POST nor $_FILE > > Best regards, > > Nicholas Yim > [EMAIL PROTECTED] > 2007-02-12 > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How to upload files up to 40MB with a html post form?
Sergiu Voicu wrote: In the second case, and if PHP isn't in safe mode, at the beggining of your script place this line ini_set("upload_max_filesize","41M"); ini_set() will have no effect there because by the time the script is executed, the upload has finished. You can probably use php_value to set it in the .htaccess - that depends on the setting of AllowOverride and that php is running as an apache module. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Retrieve value of newly inserted row.
Dan Shirah wrote: On my second insert statement, please note "credit_card_id". This is an auto_increment column in table1. What I need to do is pull the value of "credit_card_id" from the newly inserted row from insert1 and put that value in a variable to assign it to "credit_card_id" in insert2. Just append "; SELECT @@identity" to the first query, then fetch the result as normal. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems processing UNIX timestamps in events directory
Dave Goodchild wrote: I have converted the user-friendly date output to timestamps to check and sure enough, when the user selects a start date before March 26 2007, March 26 2007 is output as: 1174863600 ...after that it becomes: 117486 ...a difference of 3600 Is this anything to do with leap seconds or any other clock drift phenomenon anyone has seen before? Much hair being torn out at present! That certainly looks like the end of DST (daylight saving time). HTH, Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Populating array with function
Brad Bonkoski wrote: $files[] = $entry; perhaps look into the array_push() function http://www.php.net/array_push $files[] = $entry; is perfectly fine. $thumbnailFiles=listFiles($thumbnailsDirectory); print""; print_r($thumbnailsFiles); print""; The code is fine, spot the typo. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form Handler Script Security Discussion
Many legitimate users will have their referrer blocked by proxies or by browser preference so you'll also have false negatives. Arpad cajbecu wrote: it is not safe. i can use curl (www.php.net/curl) and modify the referer of my script to pass this security check. i advise you to add image code to the form and check that in your script. that will stop the attackers insert lot of data in your database. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Duplicate dates in array
Dave Goodchild wrote: Any ideas on the most efficient way to do it? I am working on using combinations of array_search, in_array and so on and want to avoid regular expressions if I can. Many thanks in advance for any suggestions! If you mean that you only want one date for each month (you'll end up with the last one), then it's very simple: foreach ($dates as $date) { preg_match('/[a-z]{3} \d{4}/i', $date, $m); $newDates[$m[0]] = $date; } If you're really averse to regex, you could use date('Y-m', strtotime($date)) there instead, but I suspect that would perform far worse. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP "preg_replace" help
Jim Lucas wrote: Here is a nice little hack that I use. "Little hack" it is, "nice" it isn't. Ideally just turn off magic_quotes_gpc - you can do so in php.ini, or perhaps your web server configuration files (httpd.conf, .htaccess etc.). If you don't have access to any of the above then install the latest version of PHP_Compat (http://pear.php.net/package/PHP_Compat) and include 'PHP/Compat/Environment/magic_quotes_gpc_off.php'. Reversing the effects of magic_quotes_gpc at runtime is far from trivial, there's lots of potential for subtle bugs, let alone completely forgetting about $_COOKIE. If you're unable to install PHP_Compat, you can grab the relevant files from CVS: http://cvs.php.net/viewvc.cgi/pear/PHP_Compat/Compat/Environment/_magic_quotes_inputs.php?revision=1.3&view=markup http://cvs.php.net/viewvc.cgi/pear/PHP_Compat/Compat/Environment/magic_quotes_gpc_off.php?revision=1.7&view=markup Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP "preg_replace" help
Apologies if you already received this message, I tried to send it earlier from my webmail but it doesn't seem to have worked. Al wrote: Just use stripslashes() on your submitted data and forget about testing for magic_quotes. It's good practice anyhow. \" is not legit text regardless. Using stripslashes() on all submitted data is most certainly *not* good practice. If magic_quotes_gpc is later turned off or you're using one of the versions of PHP with buggy magic_quotes_gpc support then you can easily lose data. Reversing the effects of magic_quotes_gpc is far from trivial, there's lots of potential for subtle bugs, let alone completely forgetting about $_COOKIE. See my earlier reply for a real solution. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Separating words based on capital letter
Roman Neuhauser wrote: implode(' ', preg_split('~(?=[[:upper:]])~', 'FooBarBaz', -1, PREG_SPLIT_NO_EMPTY)); Or just.. preg_replace('/\B[A-Z]/', ' $0', 'FooBarBaz') Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: self:: vs this
M.Sokolewicz wrote: Basically what you can remember here is: :: calls a property or method in a STATIC context (ie. without access to the object's (if any) actual properties) -> calls a propert or method in a DYNAMIC context (ie. WITH access to that specific object's collection of methods and properties). While that's generally true, self::, parent::, ClassName:: and ParentClassName:: can all be used in both contexts when calling methods. Consider the following code: At first glance these all appear to be static method calls, but $this is available in every case. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php and Ajax problem
Richard Kurth wrote: if(response.indexOf('|' != -1)) { Spot the misplaced bracket. if($_GET['takeaction']=="delete"){ $uid=$_GET['uid']; echo $uid; This is wide open to XSS attacks, you need to be just as careful with scripts intended to be accessed via javascript as you do with user facing scripts. If uid is as it sounds, an integer, then intval($_GET['uid']) will do nicely; otherwise at least use htmlentities() to prevent XSS. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Removing Spaces from Array Values
Jim Lucas wrote: foreach ( $someArray AS $k => $v ) { $someArray[$k] = preg_replace('!\s!', '', $v);// Removes white space ' ', \n, \r\n, etc... $someArray[$k] = str_replace(' ', '', $v);// Removes only spaces } str_replace() also operates on arrays so there's no need for the loop: $someArray = str_replace(' ', '', $someArray); And if you want to replace all whitespace: $space = array(' ', "\t", "\n", "\r", "\x0B", "\x0C"); $someArray = str_replace($space, '', $someArray); Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] magic quotes
Phil Princely wrote: What do people on this list usually do with this kind of problem. To me, the .htaccess seems the easiest solution, since I don't have to change any scripts. I would certainly turn it off in php.ini or apache config files if possible (the .htaccess line should be "php_flag magic_quotes_gpc off" by the way). However, if you end up doing it at runtime, then it's best to use Environment/magic_quotes_gpc_off.php in PHP_Compat. magic_quotes_gpc has been very inconsistent between PHP versions so a generic stripslashes_array() function is unwise. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] magic quotes
Phil Princely wrote: thanks for all the help. My code was wrong in the first post, I just copied it straight from the web. This one works: if (get_magic_quotes_gpc()) { stripslashes_array($_GET); stripslashes_array($_POST); stripslashes_array($_REQUEST); stripslashes_array($_COOKIE); } set_magic_quotes_runtime(0); set_magic_quotes_runtime() has no effect on magic_quotes_gpc. function stripslashes_array(&$arr) { foreach (array_keys($arr) as $k) { $arr[$k] = stripslashes($arr[$k]); } } This function breaks arrays, ignores keys, and takes into account none of PHP's inconsistencies with magic_quotes_gpc. As I said before, if you need to do it at runtime, use the PHP_Compat code. Here's the two relevant files, if you can't use the PEAR installer: http://cvs.php.net/viewvc.cgi/pear/PHP_Compat/Compat/Environment/_magic_quotes_inputs.php?revision=1.3&view=markup http://cvs.php.net/viewvc.cgi/pear/PHP_Compat/Compat/Environment/magic_quotes_gpc_off.php?revision=1.7&view=markup I tried searching for setini, but came up with nothing, except this: setIni('magic_quotes_gpc', 'Off', $inifile); // didn't work: unknown function ini_set() is probably what you're thinking of, but magic_quotes_gpc is applied before your script is executed so it will have no effect. That's why the only option at runtime is to reverse it. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression and forbidden words
Nicolas Quirin wrote: Hi, i'm french, i'm using regular expressions in php in order to rewrite hyperlink tags in a specific way before apache output is beeing sent to client. Purpose is to replace href attribute of any A html tag by a javascript function calling an ajax loader. Currently I have wrote that: $pattern = '/(.*?)<\\/a>/i'; $replacement = '$5'; $html_mark = preg_replace($pattern, $replacement, $html_mark); it works, but it's too permissive, it replaces too much links (some links with some get parameters must stay unchanged) I don't really understand my pattern...it's a little strange for me...lol I wouldn't like to rewrite links that contains any of the following words in get parameters (query string): noLoader noLeftCol skipallbutpage skipservice i would like to rewrite only link that begin with 'http://dev.netdoor.fr' or '.' examples: http://dev.netdoor.fr/index.php?page=./comptes/index.php&noLoader&noLeftCol&idx=6&bdx=423&skipservice";>test =>must be not rewritted! name =>must be rewritted like this : name Please help me...:0) best regards nicolas The key here is (?!) - the negative assertion, it should look something like this: $p = '#href="(?:\.|http://dev.netdoor.fr)/index\.php\?page=(?![^"]*(?:noLoader|noLeftCol|skipallbutpage|skipservice))([^"]*)">(.*?)#is'; $r = 'OnClick="javascript:yui_fastLoader(\'./systeme/chargeur.php?page=$1\');">$2'; Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] repetition of tedious references
Olav Mørkrid wrote: consider the following statement: $language = isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) && $_SERVER["HTTP_ACCEPT_LANGUAGE"] != "" ? $_SERVER["HTTP_ACCEPT_LANGUAGE"] : "*"; when using strings in arrays that may be non-existing or empty, you have to repeat the reference *three* times, which gets excessive and unreadable. is there any way to only have to write $_SERVER["HTTP_ACCEPT_LANGUAGE"] only once? You can use empty() to take one of them out, since "0" is presumably also not a desired input: $language = empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? "*" : $_SERVER['HTTP_ACCEPT_LANGUAGE']; There's a new ?: operator in PHP 6 which will make that even shorter, however unlike empty(), it currently throws a notice with unset operands. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] repetition of tedious references
Olav Mørkrid wrote: i didn't know about empty. thanks! do you have a link to this new php 6 ? : convention? I haven't seen any documentation yet but it currently operates like: ($a ?: $b) === (empty($a) ? $b : $a) with the exception that if $a is unset then an E_NOTICE error is raised. It remains to be seen in the final version whether that notice is raised or that this operator exists at all Arpad it would be great if php 6 could have a solution for this. php is sweet when it's compact! On 18/07/07, Arpad Ray <[EMAIL PROTECTED]> wrote: You can use empty() to take one of them out, since "0" is presumably also not a desired input: $language = empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? "*" : $_SERVER['HTTP_ACCEPT_LANGUAGE']; There's a new ?: operator in PHP 6 which will make that even shorter, however unlike empty(), it currently throws a notice with unset operands. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Emphasizing first letter of string?
$string) { $strings[$key] = '' . $string[0] . '' . substr($string, 1); } ?> Micky Hulse wrote: Hi, It is getting late, and I do not think I am thinking clearly... What would be the best way to wrap tag around the first letter of a string? I know it has to be a combination of str_replace() and substr(), but due to my level of sleepiness I am having a lot of trouble working this one out... Basically, if a config variable == true I want my script to loop through an array of strings and emphasize the first letter of each string. Make sense? Sorry, I am pretty sleepy... Hmmm, I am betting I will discover the answer as soon as I send this email. :D Anyway, any help would be great! Cheers, Micky -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Overriding core functions
You can't just define a new function with the same name. The only way I know to literally redefine the function is using the runkit extension - http://pecl.php.net/package/runkit That allows you to rename functions as well as moving them, so you could rename it to something like old_mysql_query() then define your own mysql_query(). Arpad Alex Turner wrote: It may be possible to override the core function - I don't actually know. If you just define a new function with the same function it might work OK. The snag I see coming at you like a tonne of bricks is 'how do you call the original function once you have overridden it.'. This like like calling SUPER. in Java. AJ Peter Lauri wrote: Yes, that could solve it. However, my question was if I can override the core functions :) Similar that I can do Parent::myFunction() in a subclass, I want to do that, but with core functions :) -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 22, 2006 7:27 PM To: Peter Lauri Cc: php-general@lists.php.net Subject: Re: [PHP] Overriding core functions Peter Lauri wrote: Hi, I want to add some functionality when calling the mysql_query(): function my_query($Query) { //do stuff before mysql_query($Query); //do things after } // or something like: class PeteDB { var $conn; function PeteDB($db, $usr, $pwd, $etc) { $this->conn = mysql_connect($db, $usr, $pwd, $etc); if (!is_resource($this->conn)) die('db is useless'); // trigger_error() } function query($qry/*, $args*/) { // do stuff $r = mysql_query($qry, $this->conn); // do more stuff return $r; } } /* tada! hint: always use some kind of wrapper for things like db related functions (because it allows for stuff like this and, for instance, makes it alot easier to switch dbs - because you only have to change code in one place, not counting any db-specific sql floating around your app) */ This would just be for one project where I want to record all Queries and the result of them, creating an own logging function. I did a lot of Google, but no article that I found that take care of this subject. /Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Overriding core functions
Brad Bonkoski wrote: Some already good workarounds given for this question... BUT. Is it even possible to override a core function? Like I wrote a function called 'exit' and I got a parser error, which leads me to believe it is not even possible to override the core functions. Is this true of ALL PHP functions? -B 'exit' is a language construct like 'echo', so I don't think you'd be able to redefine that even with runkit. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] switch it button
Ford, Mike wrote: How about something like: switch Beware that PHP_SELF is injectable like several other $_SERVER variables, so you must at least encode it to prevent XSS attacks. Eg. http://example.com/foo.php/";>
Re: [PHP] Ajax and PHP: XMLHTTP
Micky Hulse wrote: Can I replace the above with some sort of XMLHTTP request? As noted, that's a javascript question. However your PHP code is vulnerable to XSS attacks; you should at least encode the output with htmlspecialchars() so that URLs like "foo.php/alert('hi');" are safe. eg. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] correctly reading binary data from http post
Marek 'MMx' Ludha wrote: I need to send large binary data over http post (so that urlencoding or base64 encoding is not an option). I use request like this: http://people.ksp.sk/~mmx/request (there is a zero byte between A and B). There are 3 bytes of data, but when I do it yields 1 (it truncates the string after the first zero byte). Is The fact you're accessing it as an element of $HTTP_POST_VARS (which should be $_POST anyway) means it's expected to be URL encoded. Instead set your request Content-Type to octet-stream and grab the whole post body at once. eg. // To send... $c = stream_context_create( array( 'http' => array( 'method' => 'post', 'header' => 'Content-Type: application/octet-stream', 'content' => "whatever you want \x00 here" ) ) ); file_get_contents('http://example.com/foo.php', false, $c); // To receive $data = file_get_contents('php://input'); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date verification
Ron Piggott (PHP) wrote: Is there a PHP function which verifies a valid date has been entered (-MM-DD)? Ron preg_match('/^(\d{4})-(\d\d)-(\d\d)\z/', $s, $m) && checkdate($m[2], $m[3], $m[1]) Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] heredoc usage [WAS:
Incidentally, a nice side effect of heredoc is that some editors (like vim) recognise <
Re: [PHP] any one can give an idea on this question ?
Sancar Saran wrote: For example I had a several php pages. In this page there was an array named $arrHede It has lots of values. in index.php $arrHede['antin']='yada'; in config.php $arrHede['kuntin']='bada'; and so. So I want to write a scrpit check all those files to get all $arrHede keys. And I do not want to include those files because of errors. Scanning all the php files with regex is probably easiest, e.g.: if (preg_match_all('/\$arrHede\[([\'"])(.*?)\1/', $contents, $matches)) { $keys = array_merge($keys, $matches[2]); } } ?> Note that if your array keys contain escaped quotes, like ['foo\'bar'], the regex would need to be a bit more complex to allow for them. Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http_build_query ... argh
Jochem Maas wrote: function inputPostQueryUnBorker($s) { return preg_replace('#(\?|&(?:amp;)?)([^=]*)=#eU', "'\\1'.str_replace(array('%5B','%5D'), array('[',']'), '\\2').'='", $s); } so how bad is it This is a bit more concise. I doubt there'd be a noticable difference in speed though: return preg_replace('#%5[bd](?=[^&]*=)#ei', 'urldecode("\0")', $s); Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http_build_query ... argh
Jochem Maas wrote: Arpad Ray wrote: return preg_replace('#%5[bd](?=[^&]*=)#ei', 'urldecode("\0")', $s); could you explain your regexp - I'd like to replace my version with your (if for no other reason than that shorter code is easier to read than longer code!) BUT until I really understand your regexp I'd feel 100% comfortable making the replacement. Basically, if we find a '=' before a '&' then we know we're in the key. The (?=) is a positive assertion, which says that the bracket must be followed by a '=', optionally with any characters except '&' in between. Here's the pattern with comments: ~ %5[bd] # the bracket (?= # must be followed by [^&]* # any characters except "&" = # then a "=" ) ~eix Regards, Arpad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php