Re: [PHP] windows 5.2.10 PHP not working with phpinfo
Use Event Viewer and log type is :Application log 2009/9/2 Fred Silsbee fredsils...@yahoo.com: I looked high and low but no syslog I am currently working under XP Prof SP3 --- On Mon, 8/31/09, hack988 hack988 hack...@dev.htwap.com wrote: From: hack988 hack988 hack...@dev.htwap.com Subject: Re: [PHP] windows 5.2.10 PHP not working with phpinfo To: Fred Silsbee fredsils...@yahoo.com Cc: php-general@lists.php.net Date: Monday, August 31, 2009, 6:35 AM Please set log_error=on,error_reporting=E_ALL,error_log=syslog in php.ini and then,see error detail in syslog. 2009/8/31 Fred Silsbee fredsils...@yahoo.com: I got 5.3 working but found out there was no php_mssql.dll for it. Somebody (who didn;t know) said I had to return to 5.2.8 but I found no 5.2.8 so I am trying 5.2.10 _problem: under IE8: http://72.47.28.128:8080/phpinfo.php with: ?php phpinfo(); ? I get : The website cannot display the page HTTP 500 Most likely causes: •The website is under maintenance. •The website has a programming error. ___ I installed : php-5.2.10-Win32-VC6-x86.zip and put php.ini in C:\PHP and C:\PHP\ext AND C:\WINDOWS, C:\WINDOWS\system and C:\WINDOWS\system32 I installed FastCGI 1.5 ! In php.ini I put : cgi.force_redirect = 0 // for CGI extension_dir = C:\PHP\ext commented out ;doc_root = C:\inetpub\wwwroot // for IIS/PWS leaving doc_root = _ IIS 5.1 properties-configuration I added .php C:\PHP\php5ts.dll GET,HEAD,POST,DEBUG Maybe php-win.exe _ I added to the XP Prof environment path ;C:\PHP\;C:\PHP\ext\ I created an environment variable (and rebooted) PHPRC = C:\PHP;C:\PHP\ext I never found any statement of the necessity of requiring CGI The instructions ramble around -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IRC and English
tedd wrote: At 2:02 PM -0700 9/1/09, Jessi Berkelhammer wrote: As a monolingual North American, I am also very uncomfortable with this thread. A rant about abbreviations/IRC jargon is an appropriate discussion for list, but criticizing how non-native English speakers write English is not. This thread began with a mention of the attitude that non-native English speakers have, as if non-native English speakers are a unified group that are are more likely to have a bad attitude than native English speakers. Of course such a generalization could make people uncomfortable. -jessi tedd wrote: At 11:16 AM -0300 9/1/09, Martin Scotta wrote: As a non-english speaker I feel very uncomfortable with this thread. You shouldn't feel uncomfortable because no one is talking about you. As a fellow monolingual North American, I feel very uncomfortable about your statement as well. Does any other monolingual North American feel the same way as I do? Please expound on your feelings about this most disheartening and distasteful topic. (Boy has this thread degenerated into some politically correct bullsh#t, huh?) Look if you are not the one using u as a substitute for you, then I don't see any support for the discomfort you may feel about this thread. But you are free to feel as it is your nature (shudder). If non-English users (or anyone else for that matter) want to use u for you that's fine -- but I'll refrain from helping them as well. I am sure that if I were writing in their language and shortened it to uncomprehending gibberish, I would receive the same treatment from them. Why is this so hard to understand -- am I using words that are two lengthy? Cheers, tedd Words that are two lengthy: of, an, to, it (etc.) Words that are too lengthy: antidisestablishmentarianism, internationalisation and that other one that begins with flocci... something Sorry tedd :) +1 on hating l33tsp34k and txtspk though (not tho). The American standardisation of English spelling did quite enough damage to the beautiful language of Shakespeare (who couldn't even spell his own name consistently), without any more neologisms creeping in. -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] CodeWorks 09
Jim Lucas wrote: Elizabeth Naramore wrote: Hey all, Just wanted to make sure you knew about php|architect's upcoming CodeWorks conference, coming to 7 cities in 14 days: - San Francisco, CA: Sept 22-23 - Los Angeles, CA: Sept 24-25 - Dallas, TX: Sept 26-27 - Atlanta, GA: Sept 28-29 - Miami, FL: Sept 30 - Oct 1 - Washington, DC: Oct 2-3 - New York, NY: Oct 4-5 Each two-day event includes a day of *in-depth PHP tutorials* and a day of *PHP conference talks* arranged across three different tracks, all presented by the *best experts* in the business. Each event is limited to 300 attendees and prices increase the closer we get to each event. Get your tickets today before we run out or the price goes up! For more information and to register, you can go to http://cw.mtacon.com. Hope to see you there! -Elizabeth Is their anything like this in the Pacific NORTH WEST?? Seattle or Portland Oregon area would be great! Or even in the rest of the world - PHP is bigger than just the USA :) -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] CodeWorks 09
2009/9/2 Peter Ford p...@justcroft.com Jim Lucas wrote: Elizabeth Naramore wrote: Hey all, Just wanted to make sure you knew about php|architect's upcoming CodeWorks conference, coming to 7 cities in 14 days: - San Francisco, CA: Sept 22-23 - Los Angeles, CA: Sept 24-25 - Dallas, TX: Sept 26-27 - Atlanta, GA: Sept 28-29 - Miami, FL: Sept 30 - Oct 1 - Washington, DC: Oct 2-3 - New York, NY: Oct 4-5 Each two-day event includes a day of *in-depth PHP tutorials* and a day of *PHP conference talks* arranged across three different tracks, all presented by the *best experts* in the business. Each event is limited to 300 attendees and prices increase the closer we get to each event. Get your tickets today before we run out or the price goes up! For more information and to register, you can go to http://cw.mtacon.com. Hope to see you there! -Elizabeth Is their anything like this in the Pacific NORTH WEST?? Seattle or Portland Oregon area would be great! Or even in the rest of the world - PHP is bigger than just the USA :) -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What I would do for UK PHP events :-( -- Luke Slater :O) this text is protected by international copyright. it is illegal for anybody apart from the recipient to keep a copy of this text. dieser text wird von internationalem urheberrecht geschuetzt. allen ausser dem/der empfaenger/-in ist untersagt, eine kopie dieses textes zu behalten.
Re: [PHP] Re: LoginShare | How to authenticate once, and login to different websites
Dear paragasu, Never heard of oAuth before, but I guess that it's complex for my purpose. But I'll take a look at it, I'll use it for the next version. Thank you so much for introducing this great tool! On Wed, Sep 2, 2009 at 5:51 AM, paragasu parag...@gmail.com wrote: why not use ready available php library OAuth? http://oauth.net/ On 9/1/09, Shawn McKenzie nos...@mckenzies.net wrote: Behzad wrote: Dear list, i'm trying to integrate two php-driven web applications, which both require the user to authenticate using a username and a password. Consider a situation where the user has logged-in to the 1st application. She clicks over a hyper-link, which directs her to the 2nd application. The challenge is to automatically authenticate the user on the 2nd application as well. i'm wondering how? Is it secure to store the username and password in the $_SESSION, and share the session between the two applications? Please let me know what do you think. Thank you in advance, -behzad Each application has a mechanism to tell whether the user is loggedin, and if so, who is loggedin. One of the most common is probably a uid or something saved in the session. If both apps are on the same domain and use the same session handler, then you just need to modify each apps login code to set the login stuff for the other app. Possibly create your own login code that sets the login for both apps. Either way, there's no need (and I wouldn't advise) to store the password in the session. If it's not too verbose you can post the login code for each. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Kind regards, -behzad
Re: [PHP] IRC and English (Bible)
At 9:40 AM +0100 9/2/09, Peter Ford wrote: The American standardisation of English spelling did quite enough damage to the beautiful language of Shakespeare (who couldn't even spell his own name consistently), without any more neologisms creeping in. Okay, Shakespeare... 2B || !2B is an example of what we were talking about. As to Shakespeare spelling his name consistently, I can't comment. But there is a story where Shakespeare assisted in the translation of the King James version of the Bible. Shakespeare was born in 1564 and supposedly worked on the Bible when he was 46 years old. The Bible was published one year later in 1611. In King James version of the Bible one can go to the 46th Psalm and count 46 words from the beginning and find the work Shake. Similarly, one can count 46 words forward from the end of the 46 Psalm and find the word Spear. For proof of the word count, here's a link (count for yourself): http://bartelby.org/108/19/46.html Was this Shakespeare's addition or a coincidence? It's probably a coincidence for I find it highly unlikely that Shakespeare influenced the writing of the Bible, but I find it interesting speculation. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] IRC and English
-Original Message- From: Peter Ford [mailto:p...@justcroft.com] Sent: 02 September 2009 09:40 Words that are two lengthy: of, an, to, it (etc.) Words that are too lengthy: antidisestablishmentarianism, internationalisation and that other one that begins with flocci... something Sorry tedd :) Ooh! Ooh! Ooh! Please, sir, I know that one: it's floccinaucinihilipilification! (God knows why I ever learnt that -- probably some pointless schoolboy challenge 40-odd years ago!! Is that the one that means the act of valuing as worthless, or am I confusing it with something else? Back on topic, I must admit that a lot of txtspk sails by without me noticing -- I suspect as a legacy of online chatting on DEC-10s back in the 70s, using 10cps teletypes, with a line length limit of 80 characters! Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
RE: [PHP] Date +30 comparison
-Original Message- From: tedd [mailto:tedd.sperl...@gmail.com] Sent: 01 September 2009 21:52 At 2:47 PM -0400 9/1/09, Andrew Ballard wrote: On Tue, Sep 1, 2009 at 1:27 PM, teddtedd.sperl...@gmail.com wrote: First get the date to seconds, like so: $today_date = '8/26/2009'; $next_date = strtotime($today_date) + (86400 * 30); No. Due to Daylight Saving Time, many time zones have two days each year when the number of seconds in a day is not 86400. Arrggg. But good to know. And if you absolutely insist on doing it this way, make sure you start in the middle of the day -- if your base time is 12:00 noon (which is what I always use in this situation), the furthest it can go because of DST is 11:00 or 13:00, which won't screw you up if all you're interested in is the date. ;) Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] CodeWorks 09
What I would do for UK PHP events :-( Something like this perhaps? http://conference.phpnw.org.uk/phpnw09/ Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] windows 5.2.10 PHP not working with phpinfo
THANKS! Here is my current situation (if you care to look at it (under the windows ) list I tried 5.3 and found out it had no php_mssql. Then I retreated to 5.2.10. Trying to get back to where I had everything worked, I downloaded 5.2.6: (1) I uninstalled cgi 1.5 (2) php.ini has: extension_dir = C:\PHP\ext ; doc_root = C:\inetpub\wwwroot commented out doc_root = ALL extensions are uncommented I only need: extension=php_mssql.dll ; **You CAN safely turn this off for IIS, in fact, you MUST.** cgi.force_redirect = 0 ntwdblib and php.ini moved to C:\WINDOWS C:\WINDOWS\system C:\WINDOWS\system32 IIS: properties-home directory-configuration C:\PHP\php5isapi.dll with GET,HOST,POST,DEBUG I also tried: php5ts.dll phpnsapi.dll only php5isapi.dll seemed to work! added to XP Prof SP3 path: ;C:\PHP;C:\PHP\ext also created (just in case) PHPRC environment variable (alongside path) containing C:\PHP;C:\PHP\ext I gave IUSR_LANDON all powers results this works:http://207.254.225.224:8080/phpinfo.php http://207.254.225.224:8080/new_black_scholes.php initial display works until I select DEMO...then: The page cannot be displayed There is a problem with a program on the page you are trying to reach, and the page cannot be displayed. Here is new_black_scholes.php ?php define( ITMAX,100); define( EPS,3.0e-7); // If the submit button has been pressed $StockPrice = $ExercisePrice = $RiskFreeRateInterest = $InstantaneousVarianceRateStocksReturn = ; $TimetoExpirationOption = $ValueCallOption = $ValuePutOption = $DeltaCalls = $DeltaPuts = ; if (isset($_POST['reset'])) { $m_s = 100.; $m_e = 100.; $m_rf = .12; $m_sigma = .1; $m_time = 365.; Black_Scholes_Main($m_s, $m_e, $m_rf, $m_sigma,$m_time, $m_c, $m_p, $m_deltacalls, $m_deltaputs); $StockPrice = $m_s; $ExercisePrice = $m_e; $RiskFreeRateInterest = $m_rf; $InstantaneousVarianceRateStocksReturn = $m_sigma; $TimetoExpirationOption = $m_time; $ValueCallOption = $m_c; $ValuePutOption = $m_p; $DeltaCalls = $m_deltacalls; $DeltaPuts = $m_deltaputs; } elseif (isset($_POST['submit'])) { $m_s = $_POST['StockPrice']; $m_e = $_POST['ExercisePrice']; $m_rf = $_POST['RiskFreeRateInterest']; $m_sigma = $_POST['InstantaneousVarianceRateStocksReturn']; $m_time = $_POST['TimetoExpirationOption']; Black_Scholes_Main($m_s, $m_e, $m_rf, $m_sigma,$m_time, $m_c, $m_p, $m_deltacalls, $m_deltaputs); $StockPrice = $m_s; $ExercisePrice = $m_e; $RiskFreeRateInterest = $m_rf; $InstantaneousVarianceRateStocksReturn = $m_sigma; $TimetoExpirationOption = $m_time; $ValueCallOption = $m_c; $ValuePutOption = $m_p; $DeltaCalls = $m_deltacalls; $DeltaPuts = $m_deltaputs; } function Black_Scholes_Main($m_s, $m_e, $m_rf, $m_sigma, $m_time, $m_c, $m_p, $m_deltacalls, $m_deltaputs) { $m_c = black_scholes($m_s, $m_e, $m_rf, $m_sigma, $m_time/365., $nd1, $nd2); $m_p = $m_e / pow(1.+$m_rf, $m_time/365.) - $m_s + $m_c; $m_deltacalls = $nd1; $m_deltaputs = $nd1 - 1.; } function black_scholes( $s, $e, $rf, $sigma, $time, $nd1, $nd2) { $num = log($s/$e)+$time*($rf+.5*$sigma*$sigma); $d1 = $num/($sigma*sqrt($time)); $d2 = $d1 - $sigma*sqrt($time); $c = $s*myerf($d1) - $e * myerf($d2) * exp(-$rf*$time); $nd1 = myerf($d1); $nd2 = myerf($d2); return $c; } function gammln($xx) { $cof=array(76.18009173,-86.50532033,24.01409822, -1.231739516,0.120858003e-2,-0.536382e-5); $x=$xx-1.0; $tmp=$x+5.5; $tmp -= ($x+0.5)*log($tmp); $ser=1.0; for ($j=0;$j=5;$j++) { $x += 1.0; $ser += $cof[$j]/$x; } return -$tmp+log(2.50662827465*$ser); } function gser( $gamser, $a, $x, $gln) { $gln=gammln($a); if ($x = 0.0) { if ($x 0.0) echo x less than 0 in routine GSER; $gamser=0.0; return; } else { $ap=$a; $sum=1.0/$a; $del=$sum; for ($n=1;$n=ITMAX;$n++) { $ap += 1.0; $del *= $x/$ap; $sum += $del; if (abs($del) abs($sum)*EPS) { $gamser=$sum*exp(-$x+$a*log($x)-($gln)); return; } } echo a=$a too large, ITMAX = $itmax too small in routine GSER ; return; } } function gcf( $gammcf,$a,$x,$gln) { $gold=0.0; $fac=1.0; $b1=1.0; $b0=0.0; $a0=1.0; $gln=gammln($a); $a1=$x; for ($n=1;$n=ITMAX;$n++) { $an=(double) $n; $ana=$an-$a;
RE: [PHP] Date +30 comparison
At 4:06 PM +0100 9/2/09, Ford, Mike wrote: -Original Message- From: tedd [mailto:tedd.sperl...@gmail.com] Sent: 01 September 2009 21:52 At 2:47 PM -0400 9/1/09, Andrew Ballard wrote: On Tue, Sep 1, 2009 at 1:27 PM, teddtedd.sperl...@gmail.com wrote: First get the date to seconds, like so: $today_date = '8/26/2009'; $next_date = strtotime($today_date) + (86400 * 30); No. Due to Daylight Saving Time, many time zones have two days each year when the number of seconds in a day is not 86400. Arrggg. But good to know. And if you absolutely insist on doing it this way, make sure you start in the middle of the day -- if your base time is 12:00 noon (which is what I always use in this situation), the furthest it can go because of DST is 11:00 or 13:00, which won't screw you up if all you're interested in is the date. ;) Cheers! Mike Another good thing to know. Thanks, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generic decorators and type hinting
Is there another way to cleanly wrap method calls for timing/logging purposes? I have a possibly-evil idea that gets around type-hinting by dynamically declaring decorator classes as children of the real classes that need to be timed. You end up with as many decorators as you have classes that need to be timed, but if this is for dev/QA purposes only, that might not be a problem. This method can't have the conceptual simplicity of yours, unfortunately, because __call() will never be invoked in a child class. The original parent's methods will just be called instead. But you can still override the parent's methods with wrapper methods in the child class. I've got some sample code written that first calls get_class_methods() to list the names of all the visible methods of the parent object, then constructs code to declare a child class that overrides those methods with wrapper methods, and finally eval()s the declaration and instantiates an object of the new class. The basic concept seems to work and to get along fine with type-hinting. I'm happy to share the test code if you're interested. Not sure how it would end up working in real life, and I'm guessing there are more sophisticated ways to achieve the same concept, perhaps using the Reflection API. I suspect it also needs some refining to handle protected methods. But it might be a start. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generic decorators and type hinting
On Sep 2, 2009, at 12:17 PM, Ben Dunlap wrote: I've got some sample code written that first calls get_class_methods() to list the names of all the visible methods of the parent object, then constructs code to declare a child class that overrides those methods with wrapper methods, and finally eval()s the declaration and instantiates an object of the new class. You're right; that is evil. But, interesting idea. It turns out for my specific purposes (a generic decorator that measures a class's method execution times), a full-fledged profiler like APD is really what I need, but I'll keep this in mind for getting around the type-hinting, should the need arise again. Thanks. -- David Kurtz dku...@technorati.com
Re: [PHP] Generic decorators and type hinting
I have a possibly-evil idea that gets around type-hinting by dynamically declaring decorator classes as children of the real classes that need to be timed. You end up with as many decorators as you have classes that need to be timed, but if this is for dev/QA purposes only, that might not be a problem. You don't even need to do that; it'd generate way too much redundant code. Instead, just use interfaces. The only real downside is that all the classes you want to decorate would need to implement them and that would cause a wee bit of ugliness in the code/class declaration. But if you are fine with that, it's a perfect solution, particularly since you can type hint interfaces. interface iDecorator {} class Thing implements iDecorator {} class Timer { public static function time( iDecorator $obj ) {} } $obj = new Thing(); Timer::time( $obj ); // $obj becomes a Timer obj with $obj inside it $obj-thingMethod(); // Timer passes call to Timer-obj thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] OO and Singleton class
Maybe somebody would be interested in my solution as well: http://webreflection.blogspot.com/2009/09/php-53-singleton-fast-and-abstract.html Regards Date: Wed, 2 Sep 2009 14:02:25 +0900 From: koy...@hoge.org To: php-general@lists.php.net Subject: Re: [PHP] OO and Singleton class Hi, After PHP 5.3, there is better implements for Singleton. http://d.hatena.ne.jp/Yudoufu/20090811/1250021010 This entry was written by Japanese, but you may understand php code. :-) On Wed, Sep 2, 2009 at 07:06, Eddie Drapkinoorza...@gmail.com wrote: On Tue, Sep 1, 2009 at 5:16 PM, Paul M Fosterpa...@quillandmouse.com wrote: I'm a little fuzzy on some of the PHP implementation details for some stuff. In PHP (5 = phpversion() 5.3), I'd like a configuration class which can only effectively be instantiated once. Will the following code do this? Any other suggestions or corrections? (Code is untested. Feel free to complain about syntax.) class config { private static $cfg; // Initializes the configuration from main config file function __construct() { if (!is_array(self::$cfg)) { if (defined('CFGFILE')) { include(CFGFILE); self::$cfg = $config; } else self::$cfg = array(); } } // Returns a config item or null if not found function item($index) { if (array_key_exists($index, self::$cfg)) return self::$cfg[$index]; else return null; } // Sets a config item, optionally overwriting. // Returns true on success, false on failure. function set($index, $value, $overwrite = true) { $write = false; if (array_key_exists($index, self::$cfg) and $overwrite) $write = true; elseif (!array_key_exists($index, self::$cfg)) $write = true; if ($write) { self::$cfg[$index] = $value; return true; } else return false; } }; Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The primary thing you need to do to make a class a singleton is disallow the instantiation of a class directly. Which means using visibility, which is conspicuously absent from your example above. So, to prevent normal instantiation, we make the constructor private. Also, we need a method to retrieve the instance. Static members serve this purpose: class Singleton { private static $instance; private function __construct() { } public static function getInstance() { if( ! self::$instance instanceof Singleton) //replace Singleton with class name self::$instance = new Singleton; //replace Singleton with class name return self::$instance; } public function __clone() { throw new Exception('Cannot clone a Singleton'); } } This class shell will prevent people from instantiating it ($foo = new Singleton is an error). Instead, deployment will look like `$foo = Singleton::getInstance()` which, as you can tell, always returns the same instance. Throwing an exception out of __clone() will prevent something like `$foo = Singleton::getInstance(); $bar = clone $foo;` which is something I see overlooked a lot. So, if you wanted to convert your full class to a singleton it would look something like: class config { private static $instance; private static $cfg; private function __construct() { if(!is_array(self::$cfg)) { if(defined('CFGFILE')) { include(CFGFILE); self::$cfg = $config; } else { self::$cfg = array(); } } } public function getInstance() { if(!(self::$instance instanceof config)) { self::$instance = new config(); } return self::$instance; } public function __clone() { throw new Exception(Cannot clone a Singleton.); } public function item($index) { if(array_key_exists($index, self::$cfg)) return self::$cfg[$index]; else return null; } // Sets a config item, optionally overwriting. // Returns true on success, false on failure. function set($index, $value, $overwrite = true) { $write = false; if (array_key_exists($index, self::$cfg) and $overwrite) { $write = true; } elseif (!array_key_exists($index, self::$cfg)) {
[PHP] Array references - how to unset() ?
$ARR = array( 'a' = array('b' = 'blah') ); function set($key) { global $ARR; foreach ($key as $i = $k) { if ($i == 0) { $sourcevar = $ARR[$k]; } else { $sourcevar = $sourcevar[$k]; } } // unset($sourcevar); // will cancel the reference - we want to unset the ['b'], but how? $sourcevar = null; // will set it NULL, but won't unset... foreach ($ARR ... // I could run a cleanup, that would go through all of the array and unset what is NULL, but I would need to use REFERENCES again!! array_walk_recursive() is also worthless... any ideas? } set( array('a', 'b') ); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array references - how to unset() ?
Martin Zvarík wrote: $ARR = array( 'a' = array('b' = 'blah') ); function set($key) { global $ARR; foreach ($key as $i = $k) { if ($i == 0) { $sourcevar = $ARR[$k]; } else { $sourcevar = $sourcevar[$k]; } } // unset($sourcevar); // will cancel the reference - we want to unset the ['b'], but how? $sourcevar = null; // will set it NULL, but won't unset... foreach ($ARR ... // I could run a cleanup, that would go through all of the array and unset what is NULL, but I would need to use REFERENCES again!! array_walk_recursive() is also worthless... any ideas? } set( array('a', 'b') ); unset( $ARR[$k] ) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generic decorators and type hinting
code. Instead, just use interfaces. The only real downside is that all the classes you want to decorate would need to implement them and that would cause a wee bit of ugliness in the code/class declaration. Can you explain a bit more? As I understood the OP, the challenge was to take a large, already-built code base that relies on Zend Framework (which itself has 1600 classes), and wrap arbitrary existing methods with timing logic -- without significant code changes. As I understand your solution, it would require all pre-existing classes to be modified to implement the iDecorator interface -- and even then, pre-existing methods in those pre-existing classes would not actually be affected. So those would have to be modified also. But maybe I'm totally missing something? Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array references - how to unset() ?
Robert Cummings napsal(a): Martin Zvarík wrote: $ARR = array( 'a' = array('b' = 'blah') ); function set($key) { global $ARR; foreach ($key as $i = $k) { if ($i == 0) { $sourcevar = $ARR[$k]; } else { $sourcevar = $sourcevar[$k]; } } // unset($sourcevar); // will cancel the reference - we want to unset the ['b'], but how? $sourcevar = null; // will set it NULL, but won't unset... foreach ($ARR ... // I could run a cleanup, that would go through all of the array and unset what is NULL, but I would need to use REFERENCES again!! array_walk_recursive() is also worthless... any ideas? } set( array('a', 'b') ); unset( $ARR[$k] ) Cheers, Rob. Thanks for reply, but I want to: unset($ARR['a']['b']) Imagine I have this: $KEYS = array('a', 'b', 'c'); And I want to: unset($ARR['a']['b']['c']) It's probably impossible, unless I do something dirty like this: list($rootA, $rootB, $rootC) = $KEYS; if (isset($rootC)) unset($x[$rootA][$rootB][$rootC]); elseif (isset($rootB)) unset($x[$rootA][$rootB]); elseif (isset($rootA)) unset($x[$rootA]); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array references - how to unset() ?
Martin Zvarík wrote: Robert Cummings napsal(a): Martin Zvarík wrote: $ARR = array( 'a' = array('b' = 'blah') ); function set($key) { global $ARR; foreach ($key as $i = $k) { if ($i == 0) { $sourcevar = $ARR[$k]; } else { $sourcevar = $sourcevar[$k]; } } // unset($sourcevar); // will cancel the reference - we want to unset the ['b'], but how? $sourcevar = null; // will set it NULL, but won't unset... foreach ($ARR ... // I could run a cleanup, that would go through all of the array and unset what is NULL, but I would need to use REFERENCES again!! array_walk_recursive() is also worthless... any ideas? } set( array('a', 'b') ); unset( $ARR[$k] ) Cheers, Rob. Thanks for reply, but I want to: unset($ARR['a']['b']) Imagine I have this: $KEYS = array('a', 'b', 'c'); And I want to: unset($ARR['a']['b']['c']) This is possible. You're just not giving enough consideration to your exit strategy :) ?php function unset_deep( $array, $keys ) { $final = array_pop( $keys ); foreach( $keys as $key ) { $array = $array[$key]; } unset( $array[$final] ); } $value = array ( 'a' = array ( 'b' = array ( 'c' = 'C', 'd' = 'D', 'e' = 'E' ), ), ); $keys = array('a', 'b', 'c'); unset_deep( $value, $keys ); print_r( $value ); ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Converting URL's to hyperlinks.
Maybe I misunderstood the OP, but wouldn't this (or something like it) be easier and cleaner than that mess below?? $url = preg_replace(/(\...@\w+\.[a-za-z]{2,3})/i, a href='mailto:$1'$1/a, $url); $url = preg_replace(/\s(http:\/\/)?(\w*\.?\w*\.[a-zA-Z]{2,3}.*?\s)/i, a href='http://$2' target='_blank'$2/a, $url); -Original Message- From: Nisse Engström [mailto:news.nospam.0ixbt...@luden.se] Sent: Saturday, August 29, 2009 1:46 PM To: php-general@lists.php.net Subject: Re: [PHP] Converting URL's to hyperlinks. On Fri, 28 Aug 2009 17:22:20 -0600, LinuxManMikeC wrote: a href=?php echo $url; ?click here/a *Groan* Throw any random web site to an HTML validator and you're likely to see this kind of slop all over. The correct solution is of course: $u = htmlspecialchars ($url); echo a href=\$u\$u/a; [A more elaborate way to flay this feline is included below.] /Nisse /* Reworked from slightly different code. Bugs may have been introduced. */ ?php function url_to_links ($url) { if (preg_match ('@^([a-z]+://)(.*)@i', $url, $m)) { $prfx = $m[1]; $path = $m[2]; } else { return htmlspecialchars ($url); } $url_sofar = $prfx; $links = htmlspecialchars ($prfx); $segs = explode ('?', $path, 2); if (isset ($segs[1])) $query = $segs[1]; $segs = explode ('/', $segs[0]); for ($segn = 0; $segn count ($segs); $segn++) { $url_sofar .= $segs[$segn]; if (isset ($segs[$segn+1])) $url_sofar .= '/'; if ($segs[$segn] !== '') { $links .= 'a href=' . htmlspecialchars ($url_sofar) . '' . htmlspecialchars ($segs[$segn]) . '/a'; } if (isset ($segs[$segn+1])) $links .= '/'; } if (isset ($query)) { $url_sofar .= ?$query; $links .= '?a href=' . htmlspecialchars ($url_sofar) . '' . htmlspecialchars ($query) . '/a'; } return $links; } $u = 'https://ebagwa.example/abd/def/ghi?s=tu=vw=xy=z'; $u_h = htmlspecialchars ($u); $links = url_to_links ($u); header ('Content-Type: text/html'); echo _ !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd; titleurl_to_links()/title pre $u_h #x2193; $links /pre _; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array references - how to unset() ?
AHA !!! OMG... how come I did not see that!? Instead this: $array = $array[$final]; unset($array); This: unset($array[$final]); 3 AM in the morning... that must be the reason! .) Thanks. This is possible. You're just not giving enough consideration to your exit strategy :) ?php function unset_deep( $array, $keys ) { $final = array_pop( $keys ); foreach( $keys as $key ) { $array = $array[$key]; } unset( $array[$final] ); } $value = array ( 'a' = array ( 'b' = array ( 'c' = 'C', 'd' = 'D', 'e' = 'E' ), ), ); $keys = array('a', 'b', 'c'); unset_deep( $value, $keys ); print_r( $value ); ? Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Searching on AlphaNumeric Content Only
Is there is a way to search only for the alphanumeric content of field in a db? I have an itemID field that contains item #'s that include dashes, forward slashes, etc, and I want people to be able to search for an item # even if they don't enter the punctuation exactly. Here's an example: let's say there is an itemID of 4D-2448-7PS but someone omits the dashes and searches on 4D24487PS. Is it possible in PHP to have the find be successful, even if the search criteria doesn't exactly match what's stored in the field? If this is possible, I'd appreciate it if someone could just point me in the right direction so I can read up on it. Thanks, Frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
Hi, It's definitely possible to do when you do it in PHP, but not sure about on the database side. You could read all records into memory and then iterate over it with something like: $toSearch = 4D24487PS $charsToIgnore = array('-','+',...); foreach ($items as $k=$item) { $itemVal = str_replace($charsToIgnore, '', $item); if (strcmp(str_replace($charsToIgnore, '', $toSearch), $itemVal) == 0) { $return = $item; break; } } This however might use a lot of memory, but if your DB is a manageable size it should be ok. You can probably optimise it by iterating over a db result set instead of reading everything into an array. Cheers, Tim ++Tim Hinnerk Heuer++ http://www.ihostnz.com 2009/9/3 sono...@fannullone.us Is there is a way to search only for the alphanumeric content of field in a db? I have an itemID field that contains item #'s that include dashes, forward slashes, etc, and I want people to be able to search for an item # even if they don't enter the punctuation exactly. Here's an example: let's say there is an itemID of 4D-2448-7PS but someone omits the dashes and searches on 4D24487PS. Is it possible in PHP to have the find be successful, even if the search criteria doesn't exactly match what's stored in the field? If this is possible, I'd appreciate it if someone could just point me in the right direction so I can read up on it. Thanks, Frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
Is there is a way to search only for the alphanumeric content of field in a db? I have an itemID field that contains item #'s that include dashes, forward slashes, etc, and I want people to be able to search for an item # even if they don't enter the punctuation exactly. Not sure if there's anything specifically PHP-ish that will help you here, but I would be inclined to start by storing a stripped-down version of the item ID (alphanumeric characters only) in a separate column in the database table. Then, when a user enters some search data, I would remove non-alphanumeric characters, if any, from the user's input, and then search the stripped column with this normalized version of the input. If you want even fuzzier matching (inadvertent transpositions or an omitted character or two OK, for example), you might read about Levenshtein distance: http://en.wikipedia.org/wiki/Levenshtein_distance PHP has a levenshtein function but you'll have to figure out a way to use it efficiently with your data set. Or, if Levenshtein isn't quite right for your needs, the article above might at least point you in a useful direction. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php