Re: [PHP] Class Problems
Ashley Sheridan wrote: And I really would use a PHP 5 server given the choice. I've tried speaking to the hosting company a few times, but they brush me off! Hi Ashley, And how is their SLA then? Do you take full responsibility in case of a security breach? PHP 4 is way long ago and there are plenty hosting companies that do have PHP 5 and have a clear security/update policy. You, yes YOU, are their client paying their sandwich. If you are not serviced properly, they have to eat one less. Now, go on and brush them off.. Kind regards, Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Extract an element from XML
Angelo Zanetti wrote: Hi all, I have the following segment of XML: BookingReference ReferenceSource=api165432 /BookingReference Now I want to get the value of the BookingReference where the ReferenceSource = api. In other words I want to get the value 165432. I have the following code: $ItemConfirmationReference2 = $xpath-query('BookingReference ReferenceSource' , $Element); $ItemConfirmationReference = trim($ItemConfirmationReference2-item(0)-textContent); The $Element variable passes the node that contains the BookingReference node. The tricky part for me is the =api part. Thanks in advance. A Hi Angelo, Probably it is something along the lines like: $xpath-query('BookingReference/[...@referencesource=api]/'); Fairly simple and XPath is way powerful! Kind regards, Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Extract an element from XML
Aschwin Wesselius wrote: Angelo Zanetti wrote: Hi all, I have the following segment of XML: BookingReference ReferenceSource=api165432 /BookingReference Now I want to get the value of the BookingReference where the ReferenceSource = api. In other words I want to get the value 165432. I have the following code: $ItemConfirmationReference2 = $xpath-query('BookingReference ReferenceSource' , $Element); $ItemConfirmationReference = trim($ItemConfirmationReference2-item(0)-textContent); The $Element variable passes the node that contains the BookingReference node. The tricky part for me is the =api part. Thanks in advance. A Hi Angelo, Probably it is something along the lines like: $xpath-query('BookingReference/[...@referencesource=api]/'); Fairly simple and XPath is way powerful! Kind regards, Aschwin Wesselius Ah, sorry about that: $xpath-query('bookingreferen...@referencesource=api]/'); There was a '/' after BookingReference. Kind regards, Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP screenshot capture code needed
Shelley wrote: Hi all, Do you know how to generate the screenshot of some URL with PHP? Fyi, should work under linux environment. Thanks in advance. Hi, I suggest you first look in the archives of this list for possible answers before asking a question of any kind. Hint: this topic has been handled just a few weeks ago on this list. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Recursive Directory Listing
Joe Schaeffer wrote: Joe, Here is a simplified recursive version of your above statement. ?php $dir = '.'; function displayDir($dir='.') { $show = FALSE; $results = glob($dir.'/*'); foreach ( $results AS $entry ) { if ( is_dir($entry) !in_array($entry, array('.', '..')) ) { $dirs[] = $entry; $show = TRUE; } } if ( $show ) { echo 'ul'; foreach ( $dirs AS $entry ) { echo 'li', basename($entry); displayDir($entry); echo '/li'; } echo '/ul'; } } displayDir($dir); ? Hope this helps -- Jim Lucas Excellent, Jim. Thanks very much for your help. At the risk of straying too far from the original subject/call-for-help, is there a way to flag the *first* time the function runs through a ul creation? Though my design doesn't call for it now, I could see the value of styling the first level separately than the sub-directories. Hi, This one makes use of the SPL and can handle a filter. Maybe not the cleanest way, but good enough for me. function DirectoryIterator($path, $filter = FALSE) { $files = new RecursiveDirectoryIterator($path); foreach($files as $file) { if ($filter !== FALSE) { if (array_search($file-getFileName(), $filter) !== FALSE) { continue; } } if ($file-isDir()) { $name = $file-__toString(); echo str_replace(chr(92), chr(92).chr(92), $name).chr(92).chr(92).\n; DirectoryIterator($name, $filter); } } } $path = 'C:\\projects\\sites\\www.example.com\\'; DirectoryIterator($path, array('.svn'));
Re: [PHP] Waste of storage space?
Bastien Koert wrote: Thank you for your respons. I have thought of such a sorting mechanism too. But on the other hand, the biggest drawback would be that even minor changes that might be really important could get lost. And my goal is to really keep track on everything my users do. And, in the long run, the problem with the database that eventually could/will grow very large in size, is not solved. //frank ..please keep responses on list. I think you need to look at a lifetime value of the text element. Do they age at all? suggesting that you could archive them off if they are not being used after a certain period of time. You can also isolate the text portion of this to one table and then consider things like partitioning the table for speed. We do something similar here and in one table we have +22 records taking up 112Mb of space. But we can archive off eveything that is 7 years and older And lets face it, on the issue of size, disk space is cheap. Hi, Ok, disk space is cheap, but you can't avoid the access/seek time penalty on this. - Unomi -
Re: [PHP] Waste of storage space?
Bastien Koert wrote: Hi, Ok, disk space is cheap, but you can't avoid the access/seek time penalty on this. - Unomi - Properly indexed, its not that bad...after all its what Dbs do best I only mention this, that while disk space seems a unlimited resource these days the fact that a DB gets it's bottleneck here is paramount. I suggest to look up articles about this on www.mysqlperformanceblog.com to find some hints and tips to avoid most of the issues with huge disk space and record access. And BTW, 'properly indexed' is mostly easier said than done. - Unomi -
Re: [PHP] PHP XSLT caching
vladimirn wrote: Hi all, i was wondering whats the best approach to do next. I have an xml file delivered from service of my partner. On my web server (windows) i have xslt files used for xml transformation. Those files are getting bigger, so i have request to cash them and use cashed. I was thinkging about memcahce php(dunno if it will work on windows server and tbh never used it before). So i am sure that there must be several ways to cash xslt files. I google for this, but i am not sure that i found any solution i can use. What would be the best approach to solve this? I just would like to see more ideas :) LOL sure, if someone already have a good working solution i would appreciate any link or code :0) Greetings, V Hi, I believe one of the two of the XSLT implementations in PHP, does (limited) caching in itself. But I'm not in the mood to find out which one. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Method of connecting image
[EMAIL PROTECTED] wrote: Hi Is there a method of connecting the jpg image with PHP? For instance, four images tie by two in two length in side. Napura Linux Debian4 (Server) PHP 5.2.2 Apache 2.2.4 MySQL Hi, I guess you have to use a new clean image pointer (lookup the image functions of PHP), that has the size of the result size. Than you can import the four seperate images into four seperate pointers (or loop over them), and put them inside the clean image. How to do that is up to you, but it is possible to include one image into another and decide the position of it. So one or four, doesn't matter. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] PHP to get File Type
Manoj Singh wrote: Hello All, Is there any function in PHP to get the file/Mime type of any file? Any help will be appreciated. Hi, There are better and more elegant ways to do this, but I'm not aware of them. Here is what I use most of the time. You only use the filename as $value for get_mimetype(). function get_file_extension($file) { return array_pop(explode('.',$file)); } function get_mimetype($value='') { $ct['htm'] = 'text/html'; $ct['html'] = 'text/html'; $ct['txt'] = 'text/plain'; $ct['asc'] = 'text/plain'; $ct['bmp'] = 'image/bmp'; $ct['gif'] = 'image/gif'; $ct['jpeg'] = 'image/jpeg'; $ct['jpg'] = 'image/jpeg'; $ct['jpe'] = 'image/jpeg'; $ct['png'] = 'image/png'; $ct['ico'] = 'image/vnd.microsoft.icon'; $ct['mpeg'] = 'video/mpeg'; $ct['mpg'] = 'video/mpeg'; $ct['mpe'] = 'video/mpeg'; $ct['qt'] = 'video/quicktime'; $ct['mov'] = 'video/quicktime'; $ct['avi'] = 'video/x-msvideo'; $ct['wmv'] = 'video/x-ms-wmv'; $ct['mp2'] = 'audio/mpeg'; $ct['mp3'] = 'audio/mpeg'; $ct['rm'] = 'audio/x-pn-realaudio'; $ct['ram'] = 'audio/x-pn-realaudio'; $ct['rpm'] = 'audio/x-pn-realaudio-plugin'; $ct['ra'] = 'audio/x-realaudio'; $ct['wav'] = 'audio/x-wav'; $ct['css'] = 'text/css'; $ct['zip'] = 'application/zip'; $ct['pdf'] = 'application/pdf'; $ct['doc'] = 'application/msword'; $ct['bin'] = 'application/octet-stream'; $ct['exe'] = 'application/octet-stream'; $ct['class']= 'application/octet-stream'; $ct['dll'] = 'application/octet-stream'; $ct['xls'] = 'application/vnd.ms-excel'; $ct['ppt'] = 'application/vnd.ms-powerpoint'; $ct['wbxml']= 'application/vnd.wap.wbxml'; $ct['wmlc'] = 'application/vnd.wap.wmlc'; $ct['wmlsc']= 'application/vnd.wap.wmlscriptc'; $ct['dvi'] = 'application/x-dvi'; $ct['spl'] = 'application/x-futuresplash'; $ct['gtar'] = 'application/x-gtar'; $ct['gzip'] = 'application/x-gzip'; $ct['js'] = 'application/x-javascript'; $ct['swf'] = 'application/x-shockwave-flash'; $ct['tar'] = 'application/x-tar'; $ct['xhtml']= 'application/xhtml+xml'; $ct['au'] = 'audio/basic'; $ct['snd'] = 'audio/basic'; $ct['midi'] = 'audio/midi'; $ct['mid'] = 'audio/midi'; $ct['m3u'] = 'audio/x-mpegurl'; $ct['tiff'] = 'image/tiff'; $ct['tif'] = 'image/tiff'; $ct['rtf'] = 'text/rtf'; $ct['wml'] = 'text/vnd.wap.wml'; $ct['wmls'] = 'text/vnd.wap.wmlscript'; $ct['xsl'] = 'text/xml'; $ct['xml'] = 'text/xml'; $extension = get_file_extension($value); if (!$type = $ct[strtolower($extension)]) { $type = 'text/html'; } return $type; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Flow chart tool
Ashley Sheridan wrote: For complete system agnosticism, I'd create the flowchart as a series of graphics, and then put those together in a page? I'm not sure on what the best route is for blind users, so I'm hoping someone else in the group can lend a hand on this one? I would combining the scanning with putting the info into a GraphViz .dot file and use that to export it as a graphic. That way, you can interlink the overviews with each other and GraphViz finds the way to do this by itself. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Re: php framework vs just php?
Luke wrote: I can't say I've ever used a framework. I like to be in control of all of my code, plus it's much more satisfying when you write everything yourself (I've found anyway)... If I want to make use of existing code, I rather have a good understanding and a grasp of the philosophy behind it. It is all about decisions anyway, so I better know why than just think 'whatever' or 'I don't care'. Therefore I just make use of libraries. Most of it is my own code, some are just variations on existing code and I tweaked it to my needs (or philosophy). Frameworks are nice. But I've never seen any other construction work in other fields making use of frameworks without customizing it over and over again. When people build a house, they can use ready-built parts etc. But when that house is finished, it doesn't need any backwards compatability. Housing has a lot of 'standards' and regulations or best practises. But they never use another framework exactly the same way as they did before. You can say 'Software ain't the same as housing'. Correct. But there are similarities however that makes you think about what is a good practise and what not. If you have a function and it works, but it is old code, you can still reuse it, modify it and apply it. That doesn't make a need for putting the modified version back into your old project, just for the sake of 'maintainance'. If I would be in the business of building houses, I would have to use pipes, cut them off, tweak them here and there to make them fit etc. That doesn't make a need for cut them all off already and tweak them for an older project, or next projects to come. No? I rather have a good supply of small, workable, understandable pieces of code that could make up for a framework, but doesn't. I don't want a house that is built on top of a factory framework with a lot of parts that makes it cloggy and won't be used at all. That is just my idea of why I use a library, a toolkit, rather than frameworks that are oversized most of the time. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] The 'at' sign (@) variable prefix
Jochem Maas wrote: mike schreef: Mon, Oct 6, 2008 at 12:17 PM, Daniel Brown [EMAIL PROTECTED] wrote: I will get an error, but if I prefix the value with '@', [EMAIL PROTECTED]q]; The @ is an error control operator, used to buffer the output and store it in a variable - $php_errormsg. It's better to write clean, secure code, of course but sometimes error control is a good thing, too. why not just use: $query = isset($_GET['q']) ? $_GET['q'] : ''; that way it's always set. or even better (what I recommend): $query = filter_input(INPUT_GET, 'q', FILTER_SANITIZE_STRING); and get an empty string or a sanitized string, depending on if something exists. Mike's ways are both better than suppressing the error not only because error suppression in general sucks but because it's actually less performant to trigger this kind of error. I second that. The @ symbol actually does this: @action(); Becomes: $old = ini_set(“error_reporting”, 0); action(); ini_set(“error_reporting”, $old); So, if you put that a hundred times all over your code, the errors might be suppressed but your app is slow too. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Pass parameters via url inside a php cron job
Merlin Morgenstern wrote: Hi there, I would like to run a php file via cron job and there is a parameter to be passed. Unfortunatelly this does not work: # /usr/local/bin/php /home/www/create_notification_emails.php?tf=2 Could not open input file: /home/www/create_notification_emails.php?tf=2 The problem seems to be the ?tf=2 How do I pass parameters to this script? I need the same script but executed in different time frames which is passed by the parameter. Any ideas? Thank you for any hint, Merlin Hi Merlin, Commandline arguments (for things like Cron) are a bit different than URL parameters. Try lookup information on argv and argc: http://www/php.net/features.commandline -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] __autoload alternative
Shelley wrote: Hi all, Is there any way to auto load a class without using __autoload() function? As I want to load some classes under different paths, and that caused redeclare of __autoload function. Any suggestions appreciated. Hi Shelley, I believe the PECL automap extension does what you want. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Making array to string
Hunt Jon wrote: Hi, I'm new to PHP. I have an array that I would like to convert into a string. For example, I have array( 0 = Good morning, 1 = Good afternoon, 2 = Good evening, 3 = Good night ); Now I would like to convert the array to something like: Good morning Good afternoon Good evening Good night. The result has concatanation of each value, but has one space between it. If possible, I would like to insert something like \n instead of space. I've been looking into various array functions, but I have no clue where to start. Hi, This one is easy It wil 'blow' your mind... $array = array(0 = 'Good morning', 1 = 'Good night'); $str = implode(chr(10), $array); -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Email - Best practice/advice please
Tom Chubb wrote: I have generally been using the PHP mail function for sending emails from contact forms on websites, but have recently had problems with a lot of mails being delivered to junk/spam folders. I've tried loads of different headers, etc and almost every contact form on sites I've done is different. I think it's time I started standardising and using an SMTP class to send and wanted some advice from people. I'm looking at the Pear Mail package and wondering whether that would be ok, or should I just start rolling out phpmailer on all sites, in case I start to put mailing lists, etc. in the future. Basically, what do most of you do for contact/enquiry form emails? TIA Tom Hi Tom, Sorry to inform you about this. But it is a best practice (and my advice) to first search in any archive of a forum or mailinglist before asking a question regarding a subject. Sending mail via a scripting language (like PHP) is a very common subject. Therefore an anwser to your question should be somewhere in the archives. I'm pretty sure the last month this topic has been started 2 times. So, I suggest that you first go about searching in the archives (of this mailinglist for example) and if you can't figure it out, you come back. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Thank you...
Jochem Maas wrote: Jason Pruim schreef: On Sep 11, 2008, at 8:58 AM, Micah Gersten wrote: There is only 1 military service person that should be thanked for actions on 9/11 and that is the man who was brave enough to disobey orders and shoot down the flight over Pennsylvania. The rest who were involved obeyed orders and let chaos happen. There are many military men and women who for action after 9/11 deserve our thanks though. Anyone that defends their country deserves their countries thanks and appreciation. and the war's in the middle east constitute defense in what way exactly? Hi, I'm not an American (nor I ever will be), but GW declared the War himself, so he started it. There's no defense if you start a war and start attacking another country on behalf of it's citizens. What these called 'terrorists' was not on behalf on any countries authorities. BTW, I still think 9/11 is inflicted by the government of the U.S. of A. themselves, because a lot points towards their involvement and none points to anyone like Bin Laden.. Or try to anwser at least some of these questions: http://www.rense.com/general24/t500.htm If you want to get free from your government, check out these pages and at least know your rights: http://www.thinkfree.ca/ http://spiritualeconomicsnow.net/ -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] PHP on 64bit Ubuntu
Robert Cummings wrote: On Wed, 2008-09-03 at 15:42 +0200, Per Jessen wrote: alexander lind wrote: I just tested my PHP app on Ubuntu 64bit, and found that all my php scripts would consume about 5x more RAM memory there, compared to how much they use on my macbook pro (which to make things a bit more confusing also runs a 64bit OS). A page that would take up around 2.5 MB on the macbook, takes around 12 MB on the linux server. Does anyone know what might be causing this? All pointers are twice the size, same goes for the runtime stack. But he says it's 5 times the size :) Cheers, Rob. I don't get it that people still think 64-bit is twice the 'size' of 32-bit. It's like saying 2 square meters is 2 times a square meter, while actually it is 4 times a square meter. So, 64-bits don't just take twice the memory, it can take up much more than that. Like somebody else says, the integers take a lot of space, so beware of typecasting properly.. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] VCard
Hélio Rocha wrote: I there! I've writed and app that sends a sms trough a gateway, but i want to send vcard messages, it works in some phones but doesn't work in others like some recent nokias, does anyone knows the valid vcard formats? Thanks in advance! I'm here too! ;-) How far did you get searching the web? Have you read documentation about VCard formats etc.? Maybe there are even Requests For Comments (RFC's) about it. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Re: PHP editor for linux
Carlos Medina wrote: It flance schrieb: Hi, What do you think is the best php editor for linux. I'm using the Debian distribution. Thanks Hi it´s allways the same: What for Editor are you using? and blah. Please this dicussion is old and not funny anymore (i think ). The Developer which vi or nano on debian to can be a good programmer too. Regards Carlos Medina Hi, It always comes down to what someone prefers to be useful. On the other hand, some people can point out quirks in some tools so you don't have to bother trying it out. A lot of people say Vi is a very good editor, but it takes a long time to get used to it. Other editors have the also cons and pro's etc. But some editors are plain out not useful for programming. It is good to notice so you don't have to install all the thousands of editors out there. If somebody on this list already has tried the software and has arguments against it, fine let them speak out. But I do feel much against a 'my editor, my framework, my blah is better than yours' flamewar discussion for the next 3 weeks. So I think I get your point. -- Aschwin Wesselius 'What you would like to be done to you, do that to the other' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] An appeal to your better nature
Richard Heyes wrote: Hi, Seems my 1and1 server has finally gone kaput taking my website with it, and in the tradition of all good IT professionals, I have no backups. :( So this is an appeal to you to ask if you have downloaded anything from phpguru.org at all, could you please send it to me so I can try to rebuild my site. A big thanks. Hi, What does Google cache has? And the Wayback Machine (http://www.archive.org/)? Coral Cache? Bummer dude, but you've got to learn it once the hard time. On the other hand, good backup solutions just cost a lot. I'm going to have a look at my browser cache. Maybe I find something. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] An appeal to your better nature
Richard Heyes wrote: I'm going to have a look at my browser cache. Maybe I find something. Thanks. I'm sorry Richard, seems that my browser doesn't hold the history long enough. Forgive me to ask, but how come that you don't have much copies of your work? Do you work straight on your server? I've got my editor (UltraEdit Studio) setup, that it makes a backup of the file I'm editing every 5 minutes with a timestamp and the full path. Besides that, we use SVN (wich is not that difficult to setup and manage). So, if your server is your food (so to speak), you'd better take a look at the simple things that might rescue you some day. Nowadays there are little NAS devices with RAID-0 support (like My Books from Western Digital), that gives a good backup solution for a quick buck. Off course, you can always step up to better solutions and methods. Doesn't your hosting provider has a backup facility? Maybe rent another webserver (could be virtual) and mirror it with rsync? I don't know. there must be something that suits your needs. I wouldn't like to loose my stuff, but I can't afford much for the best solutions either. It's not that my job depends on it, but personal data is a big loss too. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] An appeal to your better nature
Daniel Brown wrote: On Tue, Aug 5, 2008 at 8:53 AM, Aschwin Wesselius [EMAIL PROTECTED] wrote: I wouldn't like to loose my stuff, but I can't afford much for the best solutions either. It's not that my job depends on it, but personal data is a big loss too. Tell me about it. One of the sickest feelings in the world comes when you hear your hard drive start going click click choke click Well.. I don't know about you and your empathy. But most of my sickest feelings are caused by human behavior, not hardware.. Some acts come from darker corners of a sick human mind, than the situations where Murphy's laws are famous for. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] How to jump into and loop through XML element
Ethan Whitt wrote: PHP newbie coming over from Perl. Been trying to convert some of my Perl scripts over to PHP5. I am making a request to Amazon and receiving the following response. How can I jump down to the Item element and loop through all the ones that exist. I have been trying to do this with XML Simple, but with no success. Thanks, Ethan Hi, I'm not that much an XML guru, but I use XSL for most of the XML lookups I need. I agree, it is an extra step, but it keeps the data (XML) and the code (PHP) much more separated. XSL can make use of the XPath syntax and therefore the selections of the nodes are very easy. I haven't looked into a PHP implementation of XPath or the like (if any exists). Another step the XSL can do for you is the output formatting (hence the S for Stylesheet) and transformations (some use the XSLT for that, wich is the same in my opinion). If you have different XSL files, you can have different formatting on the same data. But anyhow Simple XML should be what it's called after Simple -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] SoapClient and arrays
Marten Lehmann wrote: Hello, I'm calling a webservice that is described by a WSDL-URL using the PHP-builtin Soap client. This works fine in general. But although the response is received correct, the variable type is wrong. According to the WSDL file, the response is defined like this: s:element name=SaveResponse s:complexType s:sequence s:element minOccurs=1 maxOccurs=1 name=SaveResult type=s:boolean / s:element minOccurs=0 maxOccurs=1 name=key type=s:string / s:element minOccurs=0 maxOccurs=1 name=messages type=tns:ArrayOfMessage / /s:sequence /s:complexType /s:element This pice of code: print gettype($response). \n; var_dump($response); print $response[key]. \n; returns this: object object(stdClass)#2 (3) { [SaveResult]= bool(true) [key]= string(52) FGLHRQXVDQJXQAWBCGJWNCQKTOYFGGMJSHYQELJPSABDGUNZWBEA [messages]= object(stdClass)#3 (0) { } } Fatal error: Cannot use object of type stdClass as array in /whatever/soap.php on line 26 You can see the structure of an associative array. But PHP doesn't treat it as an array. Now with the following code, it works fine: settype($response, array); print gettype($response). \n; var_dump($response); print $response[key]. \n; This returns: array array(3) { [SaveResult]= bool(true) [key]= string(50) FGLHRQXWDWKHQPWRDCKSNYRGUKZBHCNFSXZHENMTVKEHJZQPYZ [messages]= object(stdClass)#3 (0) { } } FGLHRQXWDWKHQPWRDCKSNYRGUKZBHCNFSXZHENMTVKEHJZQPYZ But it seems a bit unhandy and a workaround, if I have to the settype() thing each time I call a webservice. Is there a simpler way? Regards Marten Hi, What about $response-key ??? What does that give? It seems to me, that $response-key will be a public property of the stdClass? -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Get Remote-Image
Konrad Priemer wrote: Moin, kann mir mal wer auf die Sprünge helfen, ich bekomme es gerade nicht geregelt ein Image on-the-fly von einem Remote-Host per fsockopen auf meinen Server zu ziehen. Irgendwo hab ich da voll die Blockade ;) Mein nichtfunktionierender Versuch: ... Gutentag, Enschuldigung fur meine Deutsche schreibe. Aber Ich habe jetzt menige Jahren kein Deutsch geschrieben. ... $out = GET .URL_REMOTE_IMAGE. HTTP/1.0\r\nHost: .$this-host.\r\nUser-Agent: GetWiki for WordPress\r\n\r\n; $fp = fsockopen($this-host, $this-port, $errno, $errstr, 30); $File = fopen(PFAD_ZUM_ASPEICHERN,wb); fwrite( $File, $out ); Was Sie hier macht is nicht richtig. Sie schreiben $out nach $File, weil $out mußt zum $fp geschrieben werden. $fp Ist die Remote Host, und $out ist die Request. Die ervolg ist das $fp gibt Sie ein Response, und konnen mit fgets() oder fread() ausgelesen worden. Wieso, $tmp = fgets($fp); Und weiter Sie konnen $tmp ins $File schreiben. fclose($File); fclose($fp); Vielleicht ist es nicht gar richtig, aber Sie konnen das doch testen. Viel Spaß mit coding. Grüße Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting info from video formats
Rene Veerman wrote: Hi. I want to enable video and flash for my CMS, but that requires that i can read at least the dimensions of a video file.. ImageMagick's identify command supposedly reads AVI and MPEG, but i can't get it to work on my avi's: C:\Users\rene\Documents\Downloadsidentify Stargate.Atlantis.S05E02.HDTV.XviD-0TV.avi identify: Not enough pixel data `Stargate.Atlantis.S05E02.HDTV.XviD-0TV.avi'. So if ImageMagick isn't the tool to use for video files, i wonder if there is any other tool that i can use to determine the size of video files. I'd like to be able to read as many of the major video formats (AVI, XVID, DIVX, QT, etc) as possible. Hi, Maybe this is something for you: http://getid3.sourceforge.net I've used an older version a while ago, but it did some video recognition too as far as I know. It's PHP, so you can look at the source too. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] getting info from video formats
Aschwin Wesselius wrote: Rene Veerman wrote: Hi. I want to enable video and flash for my CMS, but that requires that i can read at least the dimensions of a video file.. ImageMagick's identify command supposedly reads AVI and MPEG, but i can't get it to work on my avi's: C:\Users\rene\Documents\Downloadsidentify Stargate.Atlantis.S05E02.HDTV.XviD-0TV.avi identify: Not enough pixel data `Stargate.Atlantis.S05E02.HDTV.XviD-0TV.avi'. So if ImageMagick isn't the tool to use for video files, i wonder if there is any other tool that i can use to determine the size of video files. I'd like to be able to read as many of the major video formats (AVI, XVID, DIVX, QT, etc) as possible. Hi, Maybe this is something for you: http://getid3.sourceforge.net I've used an older version a while ago, but it did some video recognition too as far as I know. It's PHP, so you can look at the source too. Hi, I took a second look at the project demo and it provides the resolution of the video frame So, I think it helps. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] getting info from video formats
Rene Veerman wrote: USD 1500 for a commercial license :( That's prohibitively expensive for me atm.. Any other packages that might do the trick? Well, there's nothing wrong with taking a peek at the source code and get some idea of how they did the information gathering. Then, build your own downsized version of such a library and use it as you see fit. On Mon, Jul 28, 2008 at 11:41 AM, Aschwin Wesselius [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Rene Veerman wrote: Hi. I want to enable video and flash for my CMS, but that requires that i can read at least the dimensions of a video file.. ImageMagick's identify command supposedly reads AVI and MPEG, but i can't get it to work on my avi's: C:\Users\rene\Documents\Downloadsidentify Stargate.Atlantis.S05E02.HDTV.XviD-0TV.avi identify: Not enough pixel data `Stargate.Atlantis.S05E02.HDTV.XviD-0TV.avi'. So if ImageMagick isn't the tool to use for video files, i wonder if there is any other tool that i can use to determine the size of video files. I'd like to be able to read as many of the major video formats (AVI, XVID, DIVX, QT, etc) as possible. Hi, Maybe this is something for you: http://getid3.sourceforge.net I've used an older version a while ago, but it did some video recognition too as far as I know. It's PHP, so you can look at the source too. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Why PHP4?
n3or wrote: Compatibility to older Software of the hosters and sloth of the developers Richard Heyes schrieb: I'm interested - why are people still using PHP4? It's been over 4 years (I think) - plenty of time to upgrade to five. I think because retro is hot these daysor wasor will be again within short notice... ;-) -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Code beautifier
Richard Heyes wrote: Anyone know of an unintrusive code beautifier written specifically with in mind? Thanks. Hi, With 'what' in mind? -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Code beautifier
Richard Heyes wrote: Anyone know of an unintrusive code beautifier written specifically with in mind? With 'what' in mind? Sorry, PHP. The only one that I've used and got results with is PEAR PHP_Beautifier. But the PEAR code itself is butt ugly. I'm thinking about rewriting parts of this package for personal use, since it is useful. I just want a quick and dirty straight forward beautifier. The plugins of PHP_Beautifier are nice, so I want to use them too. In combination with CodeSniffer you can first sniff what's wrong and then beautify it. That's my two cents. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Code beautifier
Richard Heyes wrote: Anyone know of an unintrusive code beautifier written specifically with in mind? Thanks. Hi, I want to narrow down to why I looked into PHP_Beautifier from PEAR. First, it's written in PHP (and uses the PHP tokenizer at it and not some regex wizardry) and so it's not part of some IDE and therefore you don't need to get used to a new environment. Second, you can have all sorts of guidelines and call them however it suits you. You can even set up a guideline for each coworker and one main codestyle. You import the code, run your codestyle guideline on it, make your edits and right before the build, you run the main codestyle configuration. Voila, no harm done and everybody is happy. Third, I wanted it to integrate it into phpUnderControl, so I can run a CodeSniffer and maybe the Beautifier at the end bit of a build cycle if needed, make the documentation, run some unit tests etc. Something you can't do with a IDE Beautifier. The thing is, I can't read some of my coworkers code because they don't use enough white-space. I get a headache at the end of the day because I can't focus enough and have to read each line 3 times. I hate that. People saying white-space takes bytes in the filesize have a point, but the same people indent to much or awkward or use comments all over the place just for the sake of it. If your code has enough white-space and clear indenting guidelines, you sometimes don't need to comment in your code at all. I hate comments. Not only writing them, but especially trying to 'read' around them. The code explains a lot and so has the code to be. Comments only get into my way. Put 'documentation' into a document, not in a script. You can even put PHP-doc in a separate file, run the PHPDocumentor at that file and leave your script alone. I only use PHP_Beautifier to clear up the readability of the code, not to make it look nice (or beauty). If someone has problems with my code having to much white-space, so be it. They can't say it's unreadable, but I can say it about my coworkers code. So, for now I use PHP_Beautifier and not some IDE tool wich meets only half way and misses the point. Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] syntax error
Eric Butera wrote: On Mon, Jul 21, 2008 at 7:24 AM, Ronald Wiplinger [EMAIL PROTECTED] wrote: On a system with php4 and mysql 4.x I had these lines: require(../db-config); // includes $dbhost, $buname, $dbpass $db = mysql_connect($dbhost, $dbuname, $dbpass); mysql_select_db($dbname,$db); $sql = SELECT * FROM CATEGORY WHERE .; $result = mysql_query($sql,$db); $num=mysql_num_rows($result); while ($myrow = mysql_fetch_array($result)) { Moving the *.php to a php5 and mysql 5.x site I get these errors: PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ... PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ... Looking at the manual, I cannot see what I am doing wrong. bye R. Your mysql_connect is probably failing. Look at your error log or look at mysql_error() for a reason why. Probably the mysql extension is not found or not loaded (due to not being compiled with the right path or the default path in PHP is not the right one). Happened to me a couple of times. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] syntax error
Eric Butera wrote: On Mon, Jul 21, 2008 at 7:55 AM, Aschwin Wesselius [EMAIL PROTECTED] wrote: Probably the mysql extension is not found or not loaded (due to not being compiled with the right path or the default path in PHP is not the right one). Happened to me a couple of times. -- Aschwin Wesselius 'What you would like to be done to you, do that to the other' Wouldn't that be call to undefined function then? Oh my. I'm so sorry. You're absolutely right. I mixed these two. I'm a bit side-tracked today. Thanks for pointing that out. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] OpenID
Per Jessen wrote: Kevin Waterson wrote: This one time, at band camp, Alex Chamberlain [EMAIL PROTECTED] wrote: Has anybody had any success implementing an OpenID server in PHP?? Sure, I had mine all set up on oceania.net and then the domain got stolen. So, all my OpenID info went with it.. not as good an idea as it first seems. I'm curious, how does a domain get stolen ? /Per Jessen, Zürich Is it per accident that he mentioned 'oceania.net' while it's about an identification topic? The only thing I can relate Oceania to, is not such a funny story about knowing everything about people. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Optimization of PHP Code
Sancar Saran wrote: On Friday 18 July 2008 15:53:06 Manoj Singh wrote: Hello All, I am developing the web site in PHP using MYSQL database. Can you please provide me some tips to write the optimized code. Best Regards, Manoj Kumar Singh Premature optimization as root of all evil. The Fallacy of Premature Optimization: http://www.acm.org/ubiquity/views/v7i24_fallacy.html So, let's define premature please -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] What font/size do you use for programming?
tedd wrote: Hi gang: I'm running a Mac (so I know mine is a bit different size wise) but I'm currently using Veranda at 14 point for coding. Just out of curiosity, what font and size do you ppls use for your programming? Cheers, tedd 6pt Terminal font on Windows, using UltraEdit on a 22 Dell flatscreen. I'd rather use Linux and probably monospace as small as possible. In PuTTY I use 6pt Proggy's OptiSmall to hack away in Nano on the commandline. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Re: class_is_loadable?
Pulni4kiya wrote: Well reimplementing autoloading doesn't seem such a bad idea. With the integrated autoload ...there is one very stupid way of doing what you want. Something like this (I suppose you know which class is the parent of the one that is 'missing'): eval(class $class_name extends THE_PARENT {}); You can put a field with the actual class name and fill it in the constructor so you would know if it's the actual class B or just A with a different name. (What I just wrote looks very stupid... Don't laugh at me very much please. :D) I'll think of something smarter...this is the first thing that came into my mind. Btw why is it so important to use autoloading anyway? Hi, Has anybody used the PECL extension automap yet and if so, are there issues with using that to autoload or not? Greetings, Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Inspiration for a Tombstone.
Robin Vickery wrote: 2008/6/27 Brice [EMAIL PROTECTED]: A classical : ?php echo So long and thanks for all the PHP; die(); ? echo PHP_EOL; If even your kids don't know your name, since you're always busy hacking away: Rest in peace posix_getppid(); Johnny jr. Susie Melanie -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Inspiration for a Tombstone.
tedd wrote: Hi gang: For a break in our normal serious thinking, I suggested tombstone wit of: Always on the edge of greatness Dan offered: /cruelWorld or /Dan or ?php function dan($dateOfDeath) { return Daniel P. Brown: 01-01-1970 - .$dateOfDeath; } die(dan('00-00-')); ? What would you like on your Tombstone? (-- that's actually a trademarked saying) Hi, There are plenty of things that cross my mind about this: A simple end of script tag: ? But that is really vague of course. Another would be: function life($user) { while($user-days_on_earth !== COUNTED) { $user-do_stuff(); } $user-disconnect(); } Endless things possible with programming metaphors. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Redirect after pdf / file download
Yashesh Bhatia wrote: Hello: I'm trying to emulate a problem i'm trying to solve as follows. 1 - user enters information into a html form and submits 2 - a php script is invoked on the submit and a pdf file is stamped and made available for download 3 - the script finally redirects the user to a thank you html page. i'm having a problem in the redirect to the thank you page. here's the 3 files 1.html htmlbody form action=2.php method=post First Name: input type=text name=firstname / Last Name: input type=text name=lastname / input type=submit / /form /body/html 2.php ?php // some stamping code ... // open the file in a binary mode $name = 2.pdf; fp = fopen($name, 'rb'); // send headers, dump the pdf file and finally redirect header(Content-Type: application/pdf); header(Content-Disposition: attachment; filename=$name); header(Content-Length: . filesize($name)); fpassthru($fp); echo 'script type=text/javascript'; echo 'window.location.href=3.html;'; echo '/script'; ? 3.html htmlbody Thank you for downloading 2.pdf /body/html The submit works fine and the pdf is availble for download however, the redirect does not happen. If i comment the lines //header(Content-Type: application/pdf); //header(Content-Disposition: attachment; filename=$name); //header(Content-Length: . filesize($name)); //fpassthru($fp); then the redirect happens after the submit. i'm testing / running it on fedora core 6, Apache 2.2.5, php 5.2.5 and firefox 1.5 Any help / pointers is appreciated. Thanks. Yashesh Bhatia. Hi, What you are doing is: header(Content-Type: application/pdf); And after that you try to echo some script. But the browser already thinks that belongs to the PDF and not to a HTML page. What I think should work instead of the script part is just: header('Location: 3.html'); exit; But I'm not sure it works. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
[Fwd: Re: [PHP] multithreading]
hce wrote: Hi, 1. Does PHP support multithreading? Yes, it does. I suspect a reply from Manuel Lemos about a multithreading class on www.phpclasses.org at any time now.;-) No kidding, I've tested a class from phpclasses.org and it worked. Can't find the library on my computer(s) right now, so I can't give you the exact name of the package.. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] page suck attack
robert wrote: Not that i can tell. Yahoo and google have a signature: googlebot and slurp. both of them also check my site over a span of days. that's all good. The others come from regular isps as far as their IP tells me and the hits are within milliseconds. Hi, Are the URL's legit? Or are there URL's being called that cause 404 errors? Since there are bots out there scanning for vulnerable paths, like phpMyAdmin, phpBB, cgi-bin exploits etc. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dead code
Hello list, Is there anyone having experience with finding dead code in their library / application? Dead code as in unused variables, uncalled methods, uncalled functions, undeclared classes etc. Any help on examples, resources etc. is much appreciated. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] tracking Mials Which were bounced.
Chetan Rane wrote: Hi All I am using a PHP Mailer to send mass mails. How can I Identify how mails have bounced. Hi, I guess you have to read some RFC's to get an idea about e-mail protocols. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] AI file and mapping with PHP
Angelo Zanetti wrote: Hi Guys, We have a project where by we have a map in ai format (vector format). What we want to do is to programmatically come up with a solution that say on the map there is a restaurant at a certain location, that we can zoom into the map on that specific area. I really am not sure where to start. I guess image maps arent going to work are they? Should I be using the GD library for manipulating the images and doing zooming? Also will the ai format be supported? Hi Angelo, I can't find anywhere what this is about? Is it a web based solution? Is it an desktop application? Is it console based? -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Problems with mod_vhost_alias and PHP require
Mário Gamito wrote: Hi, I have this Apache server with mod_vhost_alias and set /home/pages/%0 as the VirtualDocumentRoot In /home/pages/gamito.foo.com I have a index.php file. This generates the http://gamito.foo.com URL. Also, I have a /home/pages/fckeditor with FCKeditor. *This is not defined as a subdomain in the DNS* I need to include in my index.php the file /home/pages/fckeditor/fckeditor.php I have: @define('FCKEDITOR_BASE', dirname(__FILE__)); require FCKEDITOR_BASE . '/../fckeditor/fckeditor.php'; Hi, Try this '../fckeditor/fckeditor.php' -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] How to determine if file is writable and deletable
Al wrote: I need to determine if a file is truly deletable by a php script, Deleting permissions seem to be the same as writing, they probably have the same criteria. is_writable() seems to virtually useless in most cases. It doesn't take into account the directory ownership/permissions; which, best I can tell, is the real determining factor. I've resorted to having to determine the directory's ownership and then compare the directory's rights with the owner's and then the other ['world']. E.g., Assume my script was loaded with ftp, so it's ownership is the site-name, and I want the scrip to be able to determine if it can delete a file. Thus, the file in question must have its other permissions include write. Surely, there must be an easier way. Thanks, Al Hi, Maybe this is what you need: http://nl.php.net/manual/en/function.fileperms.php -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Regex to catch ps
Ryan S wrote: Hey! Thansk for replying! clip It is obvious I haven't had my caffeine yet. This is my last try to get the pattern straight: ?php $html = END_OF_HTML bhello/b b class=blahhello/b pthose/p p class=blahhello/p ahello/a a href=urlthis/a arose/a a href=regex yohello/a anose/a a id=2 href=regex yohello/a pthat/p p class=blah title=whateverhello/p END_OF_HTML; $tags = array(); $tags[] = 'p'; $tags[] = 'a'; $attr = array(); $attr[] = 'class'; $attr[] = 'href'; $vals = array(); $vals[] = 'blah'; $vals[] = 'url'; $vals[] = 'yo'; $text = array(); $text[] = 'hello'; $text[] = 'this'; $text[] = 'that'; $tags = implode('|', $tags); $attr = implode('|', $attr); $vals = implode('|', $vals); $text = implode('|', $text); $pattern = '/('.$tags.')[^]*('.$attr.')?[^]*('.$vals.')?[^]*('.$text.')[^\/]*\/\1/i'; echo $pattern.\n; echo \n; preg_match_all($pattern, $html, $matches); var_dump($matches); ? /clip I dont get why you added this $tags[] = 'a'; Does that mean I will have to make tags like that for all the html tags that i think will be on the page? Hi, I said before that the example could be a little bit overkill, but it gives a quick example how to find any tag(s) given, with any attribute(s) given and with any text given in between the opening and closing tag. And yes, it might be incomplete or maybe not even accurate, but it does give you a headstart on your solution. There always will be people who will give you a shorter, cleaner, more beautiful example, but I hope that it was helpful for you or will be helpful for someone else. Cheers, Aschwin Wesselius
Re: [PHP] Regex to catch ps
Ryan S wrote: Hey all! To say I suck at regex is an understatement so really need any help I can get on this, I have a page of text with different html tags in them, but each block of text has a p or a class=something tag... anybody have any regex that will catch each of these paragraphs and put then into an array example: array[0]=p first block /p; array[1]=p class=blah block X/p; Thanks! R Hi, Maybe the example is overkill, but I give you a quick setup that can save you some time finding HTML tags with a certain attribute. ?php $html = END_OF_HTML bhello/b b class=blahhello/b phello/p p class=blahhello/p ahello/a a href=urlhello/a END_OF_HTML; $tags = array(); $tags[] = 'p'; $tags[] = 'a'; $tags = implode('|', $tags); $pattern = '/('.$tags.')[^]*/i'; echo $pattern.\n; preg_match_all($pattern, $html, $matches); var_dump($matches); ? I'm not an expression guru either, but I think it works OK. I had to find 'link', 'img', 'a' and other tags in HTML and used a more complex expression for it which worked like a charm. It's just an example. For you, you have to leave away the 'a' tag in the $tags array, to get what you want. Hope it helps! -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Regex to catch ps
Aschwin Wesselius wrote: Ryan S wrote: Hey all! To say I suck at regex is an understatement so really need any help I can get on this, I have a page of text with different html tags in them, but each block of text has a p or a class=something tag... anybody have any regex that will catch each of these paragraphs and put then into an array example: array[0]=p first block /p; array[1]=p class=blah block X/p; Thanks! R Hi, Maybe the example is overkill, but I give you a quick setup that can save you some time finding HTML tags with a certain attribute. Hi, I'm sorry. I didn't read your request properly. Below you'll have a correct solution: ?php $html = END_OF_HTML bhello/b b class=blahhello/b phello/p p class=blahhello/p ahello/a a href=urlthis/a ahello/a a href=regex yohello/a ahello/a a id=2 href=regex yohello/a pthat/p p class=blah title=whateverhello/p END_OF_HTML; $tags = array(); $tags[] = 'p'; $tags[] = 'a'; $attr = array(); $attr[] = 'class'; $attr[] = 'href'; $vals = array(); $vals[] = 'blah'; $vals[] = 'url'; $vals[] = 'yo'; $text = array(); $text[] = 'hello'; $text[] = 'this'; $text[] = 'that'; $tags = implode('|', $tags); $attr = implode('|', $attr); $vals = implode('|', $vals); $text = implode('|', $text); $pattern = '/('.$tags.')[^]*('.$attr.')[^]*('.$vals.')[^]*('.$text.')[^\/]*\/\1/i'; echo $pattern.\n; echo \n; preg_match_all($pattern, $html, $matches); var_dump($matches); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex to catch ps
Aschwin Wesselius wrote: Aschwin Wesselius wrote: Ryan S wrote: Hey all! To say I suck at regex is an understatement so really need any help I can get on this, I have a page of text with different html tags in them, but each block of text has a p or a class=something tag... anybody have any regex that will catch each of these paragraphs and put then into an array example: array[0]=p first block /p; array[1]=p class=blah block X/p; Thanks! R Hi, Maybe the example is overkill, but I give you a quick setup that can save you some time finding HTML tags with a certain attribute. Hi, I'm sorry. I didn't read your request properly. Below you'll have a correct solution: Hi, It is obvious I haven't had my caffeine yet. This is my last try to get the pattern straight: ?php $html = END_OF_HTML bhello/b b class=blahhello/b pthose/p p class=blahhello/p ahello/a a href=urlthis/a arose/a a href=regex yohello/a anose/a a id=2 href=regex yohello/a pthat/p p class=blah title=whateverhello/p END_OF_HTML; $tags = array(); $tags[] = 'p'; $tags[] = 'a'; $attr = array(); $attr[] = 'class'; $attr[] = 'href'; $vals = array(); $vals[] = 'blah'; $vals[] = 'url'; $vals[] = 'yo'; $text = array(); $text[] = 'hello'; $text[] = 'this'; $text[] = 'that'; $tags = implode('|', $tags); $attr = implode('|', $attr); $vals = implode('|', $vals); $text = implode('|', $text); $pattern = '/('.$tags.')[^]*('.$attr.')?[^]*('.$vals.')?[^]*('.$text.')[^\/]*\/\1/i'; echo $pattern.\n; echo \n; preg_match_all($pattern, $html, $matches); var_dump($matches); ? -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Handling Incoming Email Attachments
Nirmal Jayasinghe wrote: hello all, I'm trying to figure out a way to manipulate incoming email attachments with PHP. There'll be a special email address to which the emails with the attachments would be sent, with a number specified in the subject line. What I need to do is to grab the attachment (a photo), rename it with the number specified in the subject line, and move it onto a specific folder on the Web server [which will be running LAMP]. I couldn't find any online material describing how to manipulate incoming mail attachments. Can someone give an idea? Hi, For handling e-mail in all their sorts (believe me, it is hell), I found the PECL mailparse the best solution. It can find the attachments and their MIME-types in a snap. And all the headers are separated too. You only have to wrap functions around it to do what you want to do. Be sure to validate the attachments and do not rely on the MIME-type only. People can spoof that kind of files. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Apache child pid segfault + APD
Waynn Lue wrote: My main problem with using xdebug was that it seemed to require KDE to interpret the traces that it took, which I don't have installed on my server. I only spent 15 minutes looking at it, though, so that could be completely unjustified... Would upgrading glibc help? Hi, Recently there is a webinterface for interpreting the results of XDebug: http://blog.agoraproduction.com/index.php?/archives/67-XDebug-to-finally-get-a-Web-Frontend.html Maybe it is for your interest. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Best practices for using MySQL index
Shelley wrote: Hi all, I am currently responsible for a subscription module and need to design the DB tables and write code. I have described my table design and queries in the post: http://phparch.cn/index.php/mysql/38-MySQL-configuration/152-best-practices-for-using-mysql-index The problem is, in a short time the table will hold millions of records. So the query and index optimization is very important. Any suggestion will be greatly appreciated. Hi, While this is not a MySQL mailing list, I try to give you some hints and keep it short. Index on most integer fields only. Text fields can be indexed, but is not important when you design your DB well. Don't index just all integer fields. Keep track of the cardinality of a column. If you expect a field to have 100.000 records, but with only 500 distinct values it has no use to put an index on that column. A full record search is quicker. Put the columns with the highest cardinality as the first keys, since MySQL will find these if no index is explicitly given. You can look at an index with SHOW INDEX FROM table and this gives you a column cardinality. Try out your select statements and use EXPLAIN SELECT whatever FROM table and use some joins on other tables. This will show you which possible indexes are found and which one is being used for that query. You can sometimes force or ignore an index being used like this SELECT whatever FROM table USE INDEX (userID). Try the MySQL manual for more options. But do use the EXPLAIN statement to have a close look on the use of indexes and the use of sorting methods. Because both are important. Having a good index, but a slow sorting method won't get you good results. I hope this is a good short hint on using indexes. But becoming a master does not come over night. Try the website www.mysqlperformanceblog.com for more good solid tips on these topics. Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best practices for using MySQL index
Shelley wrote: Don't index just all integer fields. Keep track of the cardinality of a column. If you expect a field to have 100.000 records, but with only 500 distinct values it has no use to put an index on that column. A full record search is quicker. Hmmm... That's new. :) Well, to give you a good measure: keep the cardinality between 30 to 70-80 percent of your total records in a column. But sometimes your field is NULL or empty, so it really depends. You can't just put it into a standard configuration. And it also really depends on how many records a table contains etc. Besides that, benchmarking your development environment (you do have one do you?) can gives you a good idea on how your hardware and setup performs. Aschwin Wesselius
Re: [PHP] mysql_connect slowness
Waynn Lue wrote: Our site has been slowing down dramatically in the last few days, so I've been trying to figure out why. I ran some profiling scripts on our site and saw that we're spending between 3-9 seconds on mysql_connect. Then I connected to our db and saw that there were over 100 connections at the time, most of them sleeping. Is this because we don't close mysql connections until the end of script execution? How do people generally structure their code to minimize the time they keep mysql connections open? Currently all db connections go through one file, which gets included at the top of the file. One other question, is it better to open one connection, then re-use it later, or just continually open and close per db call? Thanks, Waynn Hi Waynn, I've done some tuning on MySQL last year after having similar problems. They are not all gone, but they are reduced to a minimum. I've read the following URL's to get some hints and tips: www dot databasejournal dot com/features/mysql/print.php/10897_1402311_3 www dot t-scripts dot com/mysql/ mysqldatabaseadministration dot blogspot dot com/2005/11/mysql-5-optimization-and-tuning-guide.html (I'm sorry that these URL's are not allowed due to SURBL policies, replace 'dot' with the appropiate character) It boils down to tuning your my.cnf with some altered parameters and checking the status in MySQL. It depends on how much memory is in use, how many tables you want to have open and how many connection you expect within certain periods etc. You can gain a lot with doing this. Having sleeping processes / connections is because it doesn't have a hard timeout and MySQL sometimes forgets to kill these processes. But this is because of the load. When the load decreases, MySQL is better being able to keep up with the processes. -- Aschwin Wesselius 'What you would like to be done to you, do that to the other' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: php framework vs just php?
Lester Caine wrote: 'If it isn't broken don't fix it' causes a problem when YOU know that the step change will make future development easier, but the customers keep asking - 'Can you just add XXX' :( So they actually ask for a porn site? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hack question
Al wrote: I'm still fighting my hack problem on one of my servers. Can anyone help me figure out what's the purpose of this code. The hack places this file in numerous dirs on the site, I assume using a php script because the owner is nobody. I can sort of figure what is doing; but, I can't figure out what the hacker is using it for. Incidentally, I've changed all passwords and restricted ftp to two people. I see no sign that any code is written with by site owner, i.e, ftp. And, I've looked carefully for suspect php files. Hi, If I look up the md5 digest 'aace99428c50dbe965acc93f3f275cd3', more people on the internet have (had) problems with this kind of hack. A quick md5 lookup comes with this: Ox93Mdpqme8s But that doesn't give any Google results, so nobody knows what it is for (or related to). Do you have any third party software installed? Like a BB or a CMS or whatever? When these hackers know your site/server is vulnerable they will keep on exploiting it. Even if it just means SMTP relaying for phishing or a HTTP directory for putting malware in. Keep track of your HTTP-logs and see if these URL's are being requested! Kind regards, Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hack question
Al wrote: I'm still fighting my hack problem on one of my servers. Can anyone help me figure out what's the purpose of this code. The hack places this file in numerous dirs on the site, I assume using a php script because the owner is nobody. I can sort of figure what is doing; but, I can't figure out what the hacker is using it for. Incidentally, I've changed all passwords and restricted ftp to two people. I see no sign that any code is written with by site owner, i.e, ftp. And, I've looked carefully for suspect php files. Hi, If I look up the md5 digest 'aace99428c50dbe965acc93f3f275cd3', more people on the internet have (had) problems with this kind of hack. A quick md5 lookup comes with this: Ox93Mdpqme8s But that doesn't give any Google results, so nobody knows what it is for (or related to). Do you have any third party software installed? Like a BB or a CMS or whatever? When these hackers know your site/server is vulnerable they will keep on exploiting it. Even if it just means SMTP relaying for phishing or a HTTP directory for putting malware in. Keep track of your HTTP-logs and see if these URL's are being requested! Kind regards, Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newsletter administration
Alain Roger wrote: Hi, I need to do a little CMS for managing Newsletter for 1 of my customers. as i never worked on such thing in the past, i would be glad to have your feedback. basically, web site users are registered into DB. my customer would like to send them a newsletter to promote new products and services. this newsletter should be in HTML format and send 1 by 1 to each customer. where can i find information or template how to develop such managing tool for newsletter ? i mean online, customer will create his newsletter layout and add images, links, text, and so on... to what should i pay attention ? thanks a lot, Hi, Not to disturb your agreement with your customer, but sending out newsletters is a difficult business. If your customer sends out these newsletters from his own mailserver, chances are that his mailserver becomes blacklisted. Even if the messages are legit, some people think otherwise. The result of this is, that his whole domain becomes blocked, so his business can't send normal e-mail from this domain anymore to people who use blacklists. This has nothing to do with your question about programming it in PHP etc., but I do want you to notice these impacts. On the PHP/HTML part, make your layout as strict as possible. Every e-mail client parses the HTML differently and Outlook 2007 even went back to Word HTML compatibility which is a pain in the bottom to get it right. Building good, solid templates for newsletters is not something I would like to build for any customer. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] require_once dying silently
Richard S. Crawford wrote: Hi, everyone. This one's been driving me bonkers for an hour now. Anyone have any idea why require_once would be dying silently in the script below? $CFG-dirroot = /home/rcrawford/public_html/tanktrunk/tanktrunk; $CFG-dataroot = $CFG-dirroot.'/moodledata'; require_once($CFG-dirroot/lib/setup.php); Hi, It reads as if $CFG is an object and -dirroot is not a public property of that object. So, I don't know what $CFG is, but I think the problem lays there. Also, OOP is nice and all (not to start a thread about OOP again), but putting your config into an object seems a bit overdo to me. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] base64 encode question
Sn!per wrote: encoded value is: YToyOntzOjQ6InRpbWUiO2k6MTIwNzIwODk4MjtzOjQ6Imhvc3QiO3M6MTQ6IjE5Mi4xNjguMTAuMTAwIjt9 encoded value is: YToyOntzOjQ6InRpbWUiO2k6MTIwNzIwODk4NDtzOjQ6Imhvc3QiO3M6MTQ6IjE5Mi4xNjguMTAuMTAwIjt9 encoded value is: YToyOntzOjQ6InRpbWUiO2k6MTIwNzIwODk4NTtzOjQ6Imhvc3QiO3M6MTQ6IjE5Mi4xNjguMTAuMTAwIjt9 Hi, They are not the same! If you look closely enough, only one digit in the value is different. So the base64 encoded value has to differ only some values, not the whole string. 4MjtzO is different than 4NDtzO is different than 4NTtzO You see? So, the whole string is different and thus unique. Hope this helps! -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Memory usage very high under AMD64?
Ed W wrote: RSS is staying approximately constant, ie the memory in use has not changed much VSZ, ie virtual memory has increased by more than 2x2=4. If someone has some hard experience of both platforms then please add some experience to this - however, I'm looking for some hard debugging knowhow on this, not just some handwaving estimates please Ed W Maybe still some handwaving, but my colleague forwarded me this link: http://www.bit-tech.net/bits/2007/10/16/64-bit_more_than_just_the_ram/1 I hope that's still in your interest. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Memory usage very high under AMD64?
Ed W wrote: 45MB x2 is a lot less than 215MB... Also, I would expect the actual consumption to be less than 2x since not all the data will be doubled in size..? Any other suggestions on how to debug this 5x jump in memory usage? Thanks Ed W Robert Cummings wrote: 64 bit integers are twice as big as 32 bit integers. Hi all, I'm not an expert and have no real experience with programming in a 64-bit environment. That said, I think a system will allocate not only space for 64-bit values (in simple theory twice as much as 32-bit). 64-bit is simple a factor, so calculations increase with this factor. I think the memory goes into a square ratio (NxN) instead of just saying double (Nx2). Again, I'm not a wizzkid with enough math experience. This is just my simple and humble reasoning. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] optimilize web page loading
Alain Roger wrote: Hi, i would like to know if there is a way to know how long does a web page need to be loaded into browser ? this is interesting fact for me, as i will optimilize my PHP code in order to reduce this time to minimum. i was thinking to use some timestamp but as it will be in PHP, it mean that it should take time from server and therefore it is not fully representative from client browser time needed to load page :-( purpose : mywebpage.php - 23 s before optimalization mywebpage.php - 12 s after optimalization do you have any idea ? Hi, If you make use of Firefox, you can use the Yslow extension. This will show you the bottlenecks of the page loaded (images, stylesheets, javascripts, total duration, total size etc.). -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
[PHP] Manipulating PDF
Hi, I know it is possible to create PDF's and read them within PHP. But I'm after a method to read a PDF file, analyze it (dump structure or whatever) and being able to modify it in a valid way. And with modifying I don't mean just replacing text. I want to be able to remap layout, change fonts, change standards (if possible, I don't know). In other words, I want to have full control on the PDF and output it to my definitions. At least I want to be able to analyze PDF's so maybe I can built things myself upon the format. Has anyone seen such a thing for PHP? Or does anybody has a hint how to start doing it myself (maybe examples in Python or C which can be ported)? Again, I'm not after PHPLib or FPDF, since these libraries are either old or insufficient for what I want. Thanks in advance. Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] General use of rewrite / redirect
Hi, In too many projects / scripts / examples, I see rewrites or redirects being done like (pseudocode): if (good) { do something } else { header (location: http://otherpage) exit } Is this a best practice? What arguments are there to use this kind of mechanism? I've seen form processing being done, when finished it gets a header redirect to a 'succes' page. I've seen URL's with wrong or insufficient parameters being redirected this way. I've seen too many horrible things that actually belongs into a black book of webscripting. What is your opinion about (ab)using rewrites / redirects? Do you use it quick and dirty, or is it some elegant way of controlling flow? Thanks. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] General use of rewrite / redirect
Per Jessen wrote: Yes, that's a very typical setup. When the form is processed, you send a 303 redirect to the Thank you page. That way, if the user hits the back arrow, he's taken back to the form URL, not the post URL. (which would then warn him about re-submitting etc.) Ok, fine. But why do a real redirect when a header with 303 could be sufficient? If you model good enough, there would not be a need for header(location) redirects. Or am I wrong? What is your opinion about (ab)using rewrites / redirects? Do you use it quick and dirty, or is it some elegant way of controlling flow? I think there are plenty of perfectly valid reasons for using a redirect, whether dynamically from php or via an apache config. And undoubtedly there equally many poor reason for using redirect and/or rewrite. (they're very different things, by the way). I know they're different things. I only want to start a discussion so people do understand other techniques instead of just using whatever 'works' as a solution to their problem with flow. Redirects do solve some issues, but they should be avoided whenever possible. header(location) mechanisms do come with a very huge disadvantage if you don't use them with caution. Requests are reinitialised, libraries loaded (again), DB connections setup/checked again, session lookups are being done, log write for another request etc. That's quite an impact for just not knowing what to do with flow. So, if you know what you want to handle (control) and what you want the user to see (view), one should be able to model it without the use of redirects unless it really is needed. Or is it OK, to redirect and 'simplify' the flow? -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] General use of rewrite / redirect
jeffry s wrote: Requests are reinitialised, libraries loaded (again), DB connections setup/checked again, session lookups are being done, log write for another request etc. i don't see anything wrong with this since that is the way it is. whether you redirect or not, the script will do DB connection, session lookup anyway. i simply called exit; to stop execution after the header redirect.. sorry.. if i misunderstand your point. but that is just my opinion.. Ok, let me point it out with an example: include(this); include(that); connect(db); session check That is what normally could exist on a script for every page hit. If you have a page that only does this: if (GET || POST) { process form variables header (location: thankyou) exit } else { whatever } On the thankyou: echo 'thank you' What happens is that just for submitting a form (or any process on any page), most cases all kind of libraries are included, db connection is made, sessions are checked etc. Besides the effect on PHP, the webserver does his job too, writing to logs, creating threads etc. Conclusion is 'load per page'. So what happens in short looks like this: - do heavy stuff - process page - redirect - do heavy stuff - show thank you Why not: - do heavy stuff - process page - show thank you That is my question. How do you people think about the trade-off of performance against the ease of just redirecting to another URL just to be sure a user get's to the right destination? -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] General use of rewrite / redirect
Per Jessen wrote: header(location) mechanisms do come with a very huge disadvantage if you don't use them with caution. Requests are reinitialised, libraries loaded (again), DB connections setup/checked again, session lookups are being done, log write for another request etc. That's quite an impact for just not knowing what to do with flow. I'm having difficulties following you - a plain 303 redirect to a Thank you page shouldn't cause all of that. It's an HTTP reply with the 303 and the new URL, followed by a single URL request from the browser. OK. I think I know how other people (like you) think about just requesting URL's one after another. If that's not such a performance issue for you, fine. A plain 303 redirect mostly isn't just a HTML file, it's another script (or the same script with another action falling through a switch statement, whatever). Point is: why hitting you webserver with multiple requests per user, just after submitting a form or whatever caused the redirect? If you have 2 users per day, that won't hurt. But if you have 30.000 concurrent users a minute, that could be 60.000 requests (besides all the images, stylesheets, javascripts that are being re-requested). Or am I talking nonsense? -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] What's wrong the __autoload()?
Robert Cummings wrote: It works like follows... - $z asserts $a or claims $b - $y disagrees with $a or $b or both and responds with rebuttal $h and makes claims $c, $d, sometimes $e - $z responds with rebuttal $i and often asserts a few other things that well call $f, $g - $x throws in $Q - $w throws in $wtf - $foo, $fee, and $fii join in - $someone mentions $TLC - $o calls us all immature - $SJHSKJ mentions Nazis - $x invokes Godwin's Law - $y asserts Quirk's Exception - $G_Zus resurrects point $d - $nobody wins - $r, $u, $stillWithMe Aaah. so we're just six points before the end of this thread? ;-) -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Last Friday of every month
VamVan wrote: Can you tell me how to do this ? suppose I have a date variable = '02/23/2008' i need to know if this is the last friday of february let me know. $month = 3; $year = 2008; for ($day = 31; $day = 21; $day--) { // maximum of 7 days, but february starts at 28 $tmp_time = mktime(0, 0, 0, $month, $day, $year); if (date('w', $tmp_time) === '5') { // 5 = friday return date('d-m-Y', $tmp_time); // return $day.'-'.$month.'-'.$year; // without the function it is faster off course // echo 'Yeah, friday!'; } } Something similar worked for me to find out when daylight saving time is. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] What's wrong the __autoload()?
tedd wrote: At 9:19 PM -0400 3/13/08, Robert Cummings wrote: - $z asserts $a or claims $b - $y disagrees with $a or $b or both and responds with rebuttal $h and makes claims $c, $d, sometimes $e - $z responds with rebuttal $i and often asserts a few other things that well call $f, $g - $x throws in $Q - $w throws in $wtf - $foo, $fee, and $fii join in - $someone mentions $TLC - $o calls us all immature - $SJHSKJ mentions Nazis - $x invokes Godwin's Law - $y asserts Quirk's Exception - $G_Zus resurrects point $d - $nobody wins - $r, $u, $stillWithMe Cheers, Rob. Aha, you lose. You were the first to mention Nazis. :-) Hey, at least I've learned something today. I thought he was joking about Godwin's Law and whatever. But it really exists! Nice to know. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] php cron to check and remove files
Steven Macintyre wrote: Do you already have some code? Do you got stuck somewhere? No, i didnt even know where to start with the flow; but sitting on the toilet produces wonderfull ideas! What makes sitting on a toilet any difference than sitting anywhere else? Is it a magic toiletseat? ;-) Why don't you just put a toiletseat behind your desk? Saves the effort walking down to the restroom. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] php cron to check and remove files
Steven Macintyre wrote: Hi, I need to be able to do the following procedure; retrieve all items from a mysql db table, then check to see if the files from that table exist on the server (images), if not, to clean up and remove the physical file - so that only the files from the db exist. This will run via cron Has anyone done something similar before, willing to assist me with a basic scope of actions to work on? Hi, Do you already have some code? Do you got stuck somewhere? Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A Quick Reminder....
Daniel Brown wrote: On Thu, Mar 13, 2008 at 10:06 AM, Thijs Lensselink [EMAIL PROTECTED] wrote: It's always the Dutch huh! :) It's because in our small ountry all traffic is stuck all day long. So when it finally moves it goes all directions :) Not quite as bad as they do in India. I saw this a few weeks ago and was amazed. SFW. http://www.youtube.com/watch?v=RjrEQaG5jPM Nice I bet they have some higher alertness towards other drivers instead of depending on traffic regulations. I don't say it is safe or easy, but I think they manage pretty well.. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] What's wrong the __autoload()?
Andrés Robinet wrote: why don't you show us your PHP work instead? Maybe you like RoR more because you suck at PHP. Regards, Rob Hi, can somebody please point out something to me? Did I miss something? Is there some initiation needed on this list which I've missed? How come it is acceptable for grown up (you DO have pubic hair don't you?), mature and decent people to call names and try to convince each other of having a bigger, better whatever than the other etc.? Is that PHP-list culture? Is it something to get used to? Is it the core of senior PHP-developers or what? So, explain it to me, what is it that I could have missed? Is it somewhere in the archives? Is it explained on some FAQ page? Does it take some potions by full moon on a 3rd friday in may to get into this state? It is OK do discuss a subject, to get overheated by passion, ignorance, irritation, misunderstanding or a mix of all of them. But isn't calling names and comparing bodyparts (and what not) something for kinder garten? I'm not here to preach, I'm here to learn. So initiate me, tell me what is so important that we keep putting energy into convincing somebody that he's an idiot, a dumbass, an elite RoR fetishist etc. Does it give you a good feeling? Can I try? Should I try? Is it worth it? Will I become as enlightened as some of you are? I don't want to miss out on this great experience, if it is worth it. It must be something amazing, really. If that makes the PHP community as great as it has become, I want to join and put some effort in this marvelous activity. Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Comparing files
mathieu leddet wrote: Hi all, I have a simple question : how can I ensure that 2 files are identical ? How about this ? 8-- function files_identical($path1, $path2) { return (file_get_contents($path1) == file_get_contents($path2)); } I would say, use a md5 checksum on both files: function files_identical($path1, $path2) { return (md5(file_get_contents($path1)) === md5(file_get_contents($path2))); } -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] A Quick Reminder....
Daniel Brown wrote: On Wed, Mar 12, 2008 at 11:01 AM, TG [EMAIL PROTECTED] wrote: How about something OT that we can argue about... driving on the left side of the road versus the right side. How does your country compare? Here in Pennsyltucky, a lot of people drive on the left, despite the fact that the whole US is supposed to drive on the right. It usually doesn't turn out very good. .:shakes head, solemnly:. Not very good at all. It's the French that started to drive on the right side of the road: http://users.pandora.be/worldstandards/driving%20on%20the%20left.htm But I don't know who started with top-posting which is against the netiquette RFC. People sticking with strict HTML, coding standards in PHP, valid XML, nice pixelf*cked CSS etc. and not posting below a message on a list are a bunch of hypocrites. Simple as that. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] What's wrong the __autoload()?
Greg Donald wrote: Here, let me dumb-it-down a bit: PHP doesn't have much in the way of meta-programming capabilities. Therefore one would not find it a natural thought to do much meta-programming in PHP, unless one already knew of a language where such support exists. A different example using the same logic: My Mustang doesn't have 4-wheel drive so I don't often think much about taking it through the creeks and woods by my house like my old man and I do in his Bronco that does have 4-wheel drive. A person who has never climbed a really steep hill or ran through a waist-high creek in a 4-wheel drive auto might think such a thing impossible if they were unaware of 4-wheel drive. LOL well said. Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Frameworks
Hi all, Maybe this has past the list a couple of times (just like the 'storing images in a DB' question). What I'm after is a framework that is simple, solid, compact and flexible enough to extend by myself. I'm not an OOP person. But I do use classes when I think they fit a purpose. But most of all I want a framework that has the wheels I don't want to reinvent myself but do make sense to have. Like: - Informative error-handling - DB layer, not too abstract please - Form handling - etc. What is a good framework to start with? What framework doesn't make it too complex that it says it gives you RAD but actually let's you sink in code? I don't have to develop enterprise stuff. I want to manage information for myself and maybe build a blog or whatever to play with. What let's build things quick so you can focus on things to test instead in building the surrounding elements? Again, maybe I've to dive into archives etc. But that doesn't give me answers I need I guess. Thanks in advance. Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Frameworks
Andrés Robinet wrote: I want a framework I can plug a microphone in, and talk to it, and it does the job for me (really, I need it). But I guess we are far away from that. You need it? And what happens if you won't get it in a life time? If you need REAL RAD (a la Delphi), use VCL for PHP... you'll still have to write the event handlers (you can't save yourself from coding) and you will have to stick with Codegear (you are of those who pay for software, right?). REAL RAD? Is that an acronym or is that emphasis? But no thanks. If I've paid around 1000 dollars on software, that would be a bit much. And that must have been a decade ago. If you are looking for a flexible PHP 5 framework, where each component is more or less independent of the others, try the Zend Framework. That's what is on my list of candidates, yes. If you want a lot of features bundled into a big and fat box, and you need PHP 4 support, use CakePHP. Even the way you name database tables will be affected, but if you eat a piece of the cake you are likely to want it all anyway. Wait. PHP 4? I admit that I don't use all the OOP of PHP 5, but really I don't let myself be forced to use deprecated software if it is my income. No, I haven't touched PHP 4 like 3,5 years now. If you want a flexible and easy to use PHP 4 and PHP 5 framework and you are willing to wait more than six months for each minor release, you can use CodeIgniter. Ok, that one is of my list of candidates then. If you are rich, you can pay us (the PHP-list members) to build one for you :D. It will be a complete disaster because we'll never agree on the features, but you'll entertain yourself with our discussions for months. I think I keep that in mind when I've become rich and lonely and need some entertainment. If your IQ is greater than 150 you can try writing your own. Is IQ really relevant to being capable of writing your own framework? Ok, an IQ of 70 won't get you advanced software out of your hands. I've an IQ between 160 and 170 (lost the score along the path somewhere). But I couldn't be bothered to write my own framework just to invent some wheels to have a nice ride. It could be a challenge and might even be rewarding afterwards, but in the mean while it won't get me anywhere. So much for RAD and then writing your own framework. Must be kidding ;-) OK, thanks for your input. Some points are really helpful! Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What's wrong the __autoload()?
Robert Cummings wrote: On Wed, 2008-03-12 at 16:11 -0500, Greg Donald wrote: On 3/12/08, Robert Cummings [EMAIL PROTECTED] wrote: -1 for not recognizing a rhetorical question. +2 for setting his tongue firmly in cheek and providing you with an answer to your rhetorical question. -1 for thinking rhetorical question responses mean jack. -1 for thinking +2 exists. *Yawn* -5 for not keeping this kind of childish behavior of the list (both of you) Aschwin Wesselius
Re: [PHP] Frameworks
Andrés Robinet wrote: Anyway... you will get one thousand opinions about Frameworks, and 90% of them may be correct. Choose the framework you like after playing around with some examples and having an overview of the reference manual (forgot to say, documentation is really important to get you started). Regards, Rob(inet) Thanks again. I think you've set out exactly an opinion I was after. Off course it all depends on which level one has stepped in, is now and wants to be when start using a framework. I've not taken the step to build my own or tested anything as an early adoptor on any of them. But I see that RAD makes the difference nowadays. Time is money. People want more features in less time etc. If I don't get used to a framework very soon, I'm out of business. I want to do the whole thing. I want an environment that takes a lot of fuss out of my hands: - Unit testing, never done it, but sounds reasonable. - MVC, makes sense but can be interpreted over the top. - DB abstraction The environments I've been in don't switch from DB's over night, so I don't care. I wanna see my queries and where they come from, period. I don't need no fricking querybuilding stuff. - Form handling. Validation is key. Security is important, so sanitizing input must be done as early as possible. - Error handling. Get information back from your code. I need that together with Unit testing. Should save debugging time. etc. Voila, all arguments for a good framework. Zend sounds really a stable and reliable product. I'm gonna setup a testserver and see how far it goes. BTW, any people having experience with PHP UnderControl? Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] difference in time
Lamp Lists wrote: hi to all! on one eZine site, I have to show when the article is posted but as difference from NOW. like posted 32 minutes ago, or posted 5 days ago. is there already sucha php/mysql function? thanks. Hi, I don't know about existing functions but you can use this: function time_to_units($time) { $years = floor($time / 60 / 60 / 24/ 365); $time -= $years * 60 * 60 * 24 * 365; $months = floor($time / 60 / 60 / 24 / 30); $time -= $months * 60 * 60 * 24 * 30; $weeks = floor($time / 60 / 60 / 24 / 7); $time -= $weeks * 60 * 60 * 24 * 7; $days = floor($time / 60 / 60 / 24); $time -= $days * 60 * 60 * 24; $hours = floor($time / 60 / 60); $time -= $hours * 60 * 60; $minutes = floor($time / 60); $time -= $minutes * 60; $seconds = $time; $amount = 0; $unit = ''; if ($years 0) { $amount = $years; $unit = ' year'; if ($years 1) { $unit.= 's '; } } elseif ($months 0) { $amount = $months; $unit = ' month'; if ($months 1) { $unit.= 's '; } } elseif ($weeks 0) { $amount = $weeks; $unit = ' week'; if ($weeks 1) { $unit.= 's '; } } elseif ($days 0) { $amount = $days; $unit = ' day'; if ($days 1) { $unit.= 's '; } } elseif ($hours 0) { $amount = $hours; $unit = ' hour'; if ($hours 1) { $unit.= 's '; } } elseif ($minutes 0) { $amount = $minutes; $unit = ' minute'; if ($minutes 1) { $unit.= 's '; } } elseif ($seconds 0) { $amount = $seconds; $unit = ' second'; if ($seconds 1) { $unit.= 's '; } } return $amount.$unit; } $posted = ; // some timestamp in the past $now = time(); // as current as possible $diff = ($now - $posted); echo posted .time_to_units($diff). ago; I hope this helps ;-) -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] save image in database vs folder
Børge Holen wrote: Topposting here... dont dont dont... we beat the living crap outa this one. Dont ask, do whatever you want and learn from it. Fact is that the best one is the one that works best right then and there. Dont you dare push this subject any further... On Tuesday 11 March 2008 12:00:35 jeffry s wrote: some friend of mine ague about this matter, this morning. they say, saving image in database is more professional. I am not really agree with that,since i am just a novice programmer. i am asking senior php programmer what you opinion about this? which one is better. save in database or in folder? You guys seem to be a little sensitive about the subject ;-) I think I'm gonna dive into the archives then. To see for myself what left such a scars upon that subject. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] Transferring files between computers using php
Rahul wrote: I have a small file to be transferred between two computers every few seconds. I'm using unix with a bare bones version of php, i.e. just the original thing that gets installed when I run yum install php. As there is no webserver on any of these machines, I was wondering if there is a way to transfer a small file between them and if there is, could someone be kind enough to provide me with an example please? Thank You You can use netcat (nc), but that doesn't run in daemon mode. You can use them both ways (client / server, sending / receiving). You can use them on the commandline with a cronjob or whatever. Netcat makes it possible to do this, to send content over to port 2200 of 192.168.1.1: cat textfile.txt | nc 192.168.1.1 2200 On 192.168.1.1 all you do is something like this: nc -l -p 2200 textfile.txt I don't know all the options in depth and may not work like scp does (which is way more secure). So I would go with scp in a cronjob, but netcat is still an option. -- Aschwin Wesselius social What you would like to be done to you, do that to the other /social -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Transferring files between computers using php
Peter Ford wrote: Here's overkill: use fuse to make two sshfs filesystems :) # Make some directories to mount the remote stuff onto mkdir -p mount_point_for_B mkdir -p mount_point_for_C # Use 'fuse' to make SSHFS mounts from the remotes to the new directories sshfs B:/path_to_where_the_file_ismount_point_for_B sshfs C:/path_to_where_the_file_goes mount_point_for_C # Copy the file across: repeat this step every few seconds (cron job?) cp mount_point_for_B/the_file_to_copy mount_point_for_C # Unmount the SSHFS mounts when you're finished fusermount -u mount_point_for_B fusermount -u mount_point_for_C That's overkill indeed and can make for some cool flaws on you filesystem too. When an unmount won't succeed the next execution via cron will fail since the mount point already exists etc. Every few seconds an update over to 2 systems is somehow weird. I think it is very intensive and like I said if somehow one part of the syncing 'hangs', it can fill memory or bandwidth very quickly. So, I can't still figure out what has to be done over to these computers every minute or whatever. The situation is not really clear to me. -- Aschwin Wesselius /'What you would like to be done to you, do that to the other'/
Re: [PHP] URL modification
tedd wrote: At 4:46 PM + 2/25/08, Nathan Rixham wrote: It may be a good time to throw in this .htaccess which just palms eveything [not found] off to php [.htaccess] RewriteEngine On RewriteBase / DirectoryIndex handle.urls.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /handle.urls.php [L] [/.htaccess] I use this for everything nowadays, in terms of security it also allows me to keep every script out of the web root; and joy of joys don't need to change any rules for static files, as they will always be found and thus the rules won't apply: follow? No, I don't. Please explain. Sounds cool. Hi, As far as I can follow, this looks much like a 404 redirect trick which captures all not found files/paths. Based on the extension, you can still do fun or cool stuff and get more control about virtual paths etc. As always: TIMTOWTDI, so I'm gonna play with this .htaccess rule and see if this is better than a 404 handler. Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making sure an include file works
Aschwin Wesselius wrote: Chris wrote: have you considered installing a local copy of php (and suitable webserver) so you can test it there? I'd also suggest using a revision control system (subversion or git) and have pre-commit hooks to check the syntax. It's a bit of work to set up but once it's done you'll notice a difference - just knowing how often you're changing things can be surprising. Hi, Do you mind sharing a source where I can find more information about pre-commit hooks (and especially about syntax checking hooks)? We use subversion here and it would be great to use such hooks. Thanks. Aschwin Wesselius Ah, never mind, I've found an howto myself: http://www.gmta.info/publications/php-syntax-check-through-subversion-pre-commit-hook Cheers, Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP performance
Thiago Pojda wrote: Guys, I've been asked to build a performance report for a PHP app. I can't profile it using automated tools as I don't have full access to the server, only to the application itself. It's a PHP4 Object-Oriented app, which uses ADODB as abstraction layer with a Oracle 8i databse. The system also uses a VB.NET socket server for some data manipulation. As for migrating to PHP5 I think it's crucial, but I need facts that it really runs faster than PHP4. Anyone? :) Any ideas on what might be the bottleneck? Hi Thiago, I think it depends on what the application does. You can't just point out a bottleneck just by saying which parts are used. You can however put little timing functions here and there to measure which part of an application is taking too long. Like this: $s = microtime(); do_some_stuff(); do_some_more_stuff(); $f = microtime(); echo ($f - $s).\n; This is very simple benchmarking and you need a lot of these steps to really get some idea where the bottleneck could be. A good start would be nearby query execution and results another would be with file access or remote connections. Also good to investigate are huge loops, huge arrays that are iterated over etc. Do this step by step so you are sure which part you are investigating. Otherwise you have 10 steps, 10 results and you don't know anymore where to look. Good luck. Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making sure an include file works
Chris wrote: have you considered installing a local copy of php (and suitable webserver) so you can test it there? I'd also suggest using a revision control system (subversion or git) and have pre-commit hooks to check the syntax. It's a bit of work to set up but once it's done you'll notice a difference - just knowing how often you're changing things can be surprising. Hi, Do you mind sharing a source where I can find more information about pre-commit hooks (and especially about syntax checking hooks)? We use subversion here and it would be great to use such hooks. Thanks. Aschwin Wesselius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What design patterns do you usually use?
Zoltán Németh wrote: well, if classes are not convenient for you, then sure it would take more time but only for the first time. after that, my experience is that development time is less with classes I do use classes, but mix it with procedural code and some function libraries. But I'm a self-educated webdeveloper. I just use classes since a couple of years (started PHP in 1999) and hadn't an example how to factor certain solutions for known problems. Nowadays I hear about patterns and deep OOP and design with real architecture in mind. Fine, PHP gets more mature, gets more attention and can fit in an enterprise environment (ducks.;-). But to teach myself software engineering is still a steep curve even if I've done a lot of webprogramming in the past. I can't find the time to study software engineering to a level that is desired these days for webprogramming. I'd love to follow some courses or workshops here and there, but that doesn't compare to 4 years of hardcore computer science. I also see that besides nice OOP etc. there is a need for security expertise, configuration / optimization expertise, Web x.x expertise, database expertise. I think you cannot become a guru at all these fields to a same level even if I want to and probably am able to. What I want to say is, yes classes can take some trouble away, but right now I don't have the complete skills to software engineer the whole shebang over and over. I'd rather have the job done in time than do it the 'professional engineering' way. -- Aschwin Wesselius social What you would like to be done to you, do that to the other /social -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] reverse string without strrev();
Shelley wrote: Hi all, What do you think is the best way to display string 'abcdef' as 'fedcba'? $tmp = ''; $str = 'abcdef'; for ($i = strlen($str); $i = 0; $i--) { $tmp.= $str[$i]; } echo $tmp; -- Aschwin Wesselius social What you would like to be done to you, do that to the other /social -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] reverse string without strrev();
Stut wrote: On 28 Feb 2008, at 11:30, Aschwin Wesselius wrote: Shelley wrote: Hi all, What do you think is the best way to display string 'abcdef' as 'fedcba'? $tmp = ''; $str = 'abcdef'; for ($i = strlen($str); $i = 0; $i--) { $tmp.= $str[$i]; } echo $tmp; Close, but no cigar. $i should be initialised to strlen($str)-1 otherwise you start one character beyond the end of the string. Ah, well. You're right, but it works none the less. -- Aschwin Wesselius social What you would like to be done to you, do that to the other /social -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] reverse string without strrev();
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. -- Aschwin Wesselius social What you would like to be done to you, do that to the other /social -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] output buffering in CLI script.
Jochem Maas wrote: I mean that the shebang line at the top of the included file is output to stdout even when I turn on output buffering on prior to including the file. nothing else is output but that's because the script doesn't generate any further output - it logs everything instead - and I know it runs because the relevant lines appear in the relevant log file. I don't know what goes wrong here. I took your script and it just works, so it is not your code (I guess). I've done this: $oldIFvalue = ini_set('implicit_flush', false); ob_start(); if (!include 'scrap2.php') { ob_end_clean(); } else { $output = explode(\n, ob_get_clean()); if ($output[0] preg_match('%^#!%', $output[0])) unset($output[0]); echo implode(\n, $output); } ini_set('implicit_flush', $oldIFvalue); The only difference is it echoes imploded $output. And I do a bit different preg_match ^#! instead of ^#!\/ If you can include the script you want to include, than it should work. If you can buffer output without the include file, than it should work. If you can dump $output after you've done the explode, than it should work. So, I don't know what goes wrong. -- Aschwin Wesselius social What you would like to be done to you, do that to the other /social -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php