RE: [PHP] Text from Excel csv file loaded into MySQL table
Hello, Can anyone point me to a really good end to end tutorial on extracting text from an Excel csv file and uploading it into MySQL via a PHP script? Actually, depending on the integrity of the data and the consistency of the format in the CSV file, you can do this simply and easily using just MySQL. Take a look at the following pages: MySQL = 5.0 http://dev.mysql.com/doc/refman/5.0/en/load-data.html MySQL 5.0 http://dev.mysql.com/doc/refman/4.1/en/load-data.html If the above is not an option for you, then use this: http://us2.php.net/fgetcsv Works like a charm. -K. Bear -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Iteration through letter
What surprised me was the output, which looked like this: A B C [...] Y Z AA AB AC [...] YY YZ I don't have any idea how these letters get printed out, so I'd appreciate any guesses or explanations. http://www.php.net/manual/en/language.operators.increment.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variable of current function call?
While I'm inside a function call, is it possible to know what function is currently being called? Yes. http://us2.php.net/debug_backtrace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Capturing System output
Hello, If you are working on a Linux system, you can try appending: 21 To the end of your command, so that you end up with: Mysql -u $user -p{$pass} 21 What this does is tell the shell to redirect anything from stderr to go through stdout. If you want to get -really- fancy you can use proc_open, which will give you handles for the process' stdout, stderr, and stdin. HTH, K. Bear -Original Message- From: Brad Bonkoski [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 15, 2006 10:38 AM To: Stut Cc: PHP List Subject: Re: [PHP] Capturing System output Stut wrote: Brad Bonkoski wrote: Had this problem in the past, and always programmed around it, but wondering if there is an easier way. Good Example: Creating a setup for connecting to a mysql database. Want to do something simple to make sure they have entered a valid username/password for the database. So, the idea is something like: $rc = exec(mysql -u $user -p{$pass}, $output); The problem is one error, the stderr does not go to the output array, but rather to the screen. Previously I would redirect the stderr to a file, and then evaluate the contents of the file, but is there an easier way to get this into the PHP variable with no risk of having the output make it through to the screen? I may be missing something, but why in the name of all that is holy would you want to shell out to try connecting to mysql? Why not use mysql_connect and avoid the potentially massive security hole you're building? -Stut Perhaps poor illustration of the question...the question being how to issue system like commands in PHP which would allow you to trap not only stdout, but also stderr. -Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Creating custom superglobals
Hello, You CAN create custom superglobals, but it requires that you have RunKit enabled: http://us3.php.net/runkit HTH, K. Bear -Original Message- From: Stut [mailto:[EMAIL PROTECTED] Sent: Monday, August 14, 2006 10:04 AM To: Ville Mattila Cc: php-general@lists.php.net Subject: Re: [PHP] Creating custom superglobals Ville Mattila wrote: Does the PHP environment (5.1.4) provide a way to define some custom variables as a superglobal? It would be useful for saving certain site preferences and settings that must be referred in many variables and classes, without every time writing global keyword at the beginning of a function definition. No, PHP does not allow userland to create superglobals. However, all global variables can be accessed through the $GLOBALS superglobal. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Including Google Ads
I do not want to include it only but to be able to set the keywords for the add. You do not define that. Google scans your pages and shows relevant ads according to your pages content. Actually, you can. I'm doing this for an advertising system with the company I work for right now. You set the 'google_kw' variable before including their awful JavaScript. You can also add 'google_city' and 'google_region' for more local ads, as well as some other goodies. The default behavior is for Google to crawl the page on display the relevant ads, but supplying a key word prevents them from doing this (saving you bandwidth) and giving you more control over what is displayed. This is all documented in their AdSense documentation. HTH, K. Bear -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Including Google Ads
Modifying Google's javascript code even in the slightest (such as messing around with variables) is against the AdSense terms of service, and is a good way to get your account revoked really fast. Only premium publishers that get express permission from Google are allowed to mess with those variables. It's possible that your company is a premium AdSense customer, but Mr. Antunes is almost certainly not. Interesting! Of this I was unaware. All the business stuff is taken care of by someone else. I guess where I work is considered 'premium', which is pretty darn scary when I think about it. (o; Thanks for the heads up, I've been considering adding some ad stuff to a few small sites of my own. Regards, Adam Zey. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Is this really a pdf?
If your server has the appropriate programs installed, there ARE some command line utilities that can take a PDF and convert it to another form; You can execute them with an exec call. Theoretically, if the PDF is corrupt they will print out some kind of error which you can capture. It could also take up a ton of processing power if you do a lot of this, so be careful on the implementation. (o: I don't know if this is an option for you or not, but it is something that was done at my last company to verify that uploaded PDFs were at least readable by -something-. For Linux there is pdf2ps, and iirc there is some other program out there that just pulls out the text. HTH, -K.Bear -Original Message- From: Sjef [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 08, 2006 6:09 AM To: php-general@lists.php.net Subject: Re: [PHP] Is this really a pdf? Thanxs very much guys! I do realize that it is not foolproof, but better than nothing. In my situation mime_content_type doesn't work, so I will have to settle for the other method. Sjef -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Return Values Copied? Copied if By Reference?
Robert Cummings wrote: Then how come when I do a foreach on an array (without modifying anything within the foreach), it still makes a copy of the array that consumes memory? I think it's dangerous to generalize that it's always best to let PHP make copies of things. In the foreach situation, the preferred solution when memory is a problem is to either use a reference, or have foreach iterate over the keys of the array. Regards, Adam. - PHP doesn't seem to make a real copy of data until one of the copies is modified, making it necessary to create a new set of data. So, it is pretty smart about that. Here is a small CLI script that seems to support this: ?php $a_array = array(); for($i = 0; $i 1; $i++) { $a_array[] = time(); // Just an arbitrary piece of data } echo 'Memory Usage: ' . memory_get_usage() . \n; echo Making a copy of the array.\n; $a_copy = $a_array; echo 'Memory Usage: ' . memory_get_usage() . \n; echo Modifying the copy:\n; $a_copy[] = time(); echo 'Memory Usage: ' . memory_get_usage() . \n; ? On my machine, this displays: Memory Usage: 640280 Making a copy of the array. Memory Usage: 640440 Modifying the copy: Memory Usage: 1106056 -K. Bear -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Basic PHP knowledge test
Does anyone have any links/resources for a basic php knowledge test? If not, I'll have to write one from scratch myself, and mess up the rest of my day of goofing off/sleeping. It wouldn't hurt to pick up one of those Zend PHP Certification study guides and pull some things from there. Or, browse the PHP manual for commonly used functions and ask questions from there. What might work better though would be to pull some questions from this mailing list and ask them how they would answer them. It will give you some insight into their knowledge of PHP as well as how well they can solve problems using the language. That, in my (not so) humble opinion, is better than just knowledge of the language. You need to know how to apply it to be a decent programmer. HTH. I would be very interested in seeing what you come up with, actually. (o: -K. Bear -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] List Nastiness (Was: RE: [PHP] Zend Studio, phpMyAdmin, and mysql.sock)
Thanks Mr. Rasmussen. (o: To the rest: There has been quite a bit of mean spiritedness on the list lately. I don't know if it is the weather, some strange astrological phenomenon, or something else entirely, but can we tone it down a bit? There has been way too much flame war-esque behavior lately. We're supposed to help each other here, no? Can't we all just get along? If someone says something nasty it's possible to just ignore it. Let it go. If you -need- to retort, then I would appreciate it if it was taken off list. Thanks! In any case, this list is called PHP general. Am I really so unreasonable in thinking that asking about how to set up a PHP development environment so that I can debug my PHP scripts without it conflicting with the PHP database administration system is on-topic? In your Zend folder there is a folder called bin. In that folder you should see to other folders: php4 and php5. In each of those folders you should fine a file called php.ini. In that file add the following instruction: mysql.default_socket=/path/to/mysqld.sock -- Hilsen/Regards Michael Rasmussen http://keyserver.veridis.com:11371/pks/lookup?op=getsearch=0xE3E80917 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Debugging Log
http://pear.php.net/package/Log/ works well for me. Supports writing messages to files, to a separate window via JavaScript, probably syslog as well as a few others. -Original Message- From: Michael B Allen [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 12, 2006 2:02 PM To: php-general@lists.php.net Subject: [PHP] Debugging Log What is the standard method of logging debug info? Should I just fopen a file for append and write the message or is there a facility provided? Mike -- Michael B Allen PHP Extension for SSO w/ Windows Group Authorization http://www.ioplex.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] require_once and E_WARNING?
chris smith wrote: try it with a call to an undefined function e.g.: $foo = thisFunctionDoesNotExistAtLeastItHadBetterNot(); When this is done, the error handler doesn't get called at all, and the script simply dies with an error message (which could be a bug as well, but might also be considered a 'parse error' even if it happens at runtime; I doubt they would fix it). I read through the set_error_handler() documentation again though, and I found that: The following error types cannot be handled with a user defined function: E_ERROR[...] So, I'm guessing that the require() functions raise an E_WARNING before the E_ERROR. Seems odd. Perhaps what happens under the hood is that require() calls include(), which would raise an E_WARNING when it fails, then the require() code checks the result of include() and if it failed then it raises the E_ERROR. It pays to RTFM more closely, it seems. (o; My bad. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Problem using fgetcsv()
I am using the fgetcsv() function to read and into an array and update a database. It works great except for the odd record. After investigating, I have ascertained that it is due to a backslash character in the data which fgetcsv() cannot parse properly. I don;t see anyway around this using fgetcsv(). Has anyone written a custom routine for this? From what I understand, there are multiple CSV formats. The first one I stumbled across specified that the only character escaped inside of a string is , which is printed twice like this. However, after reading some of he user comments in the manual, it seems that MS Excel also accepts \ as an escaped quote and the PHP code follows suit. A quick search in bugs.php.net pulls up this: http://bugs.php.net/bug.php?id=29278 Categorized as a bogus bug, with the standard reply of read the manual and Escaping makes the parser skip over that character. So I guess they're not going to change it. Should be in the documentation, though. You might be better off replacing any \ sequences with \\ before reading from the file (or, if you want to be really fancy, read the file into memory, to the replaces, then use a fopen wrapper to treat the variable like a file so fgetcsv will read from it properly). Hope that helps. -KBear -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] global class instance
hi all, i wonder if there is a way of creating an instance of a class and reach it direcly from any scope in PHP4. basically what i want is: i don't want to: - declare global $foo, - use pre-defined $GLOBALS variable, - or use a::print thanks. Static is your friend. http://www.horde.org/papers/kongress2002-design_patterns/11_singleton_impl.x ml.html Also, if using PHP 4, make sure to read the References with global and static variables section. It doesn't work quite the way a lot of people expect it to. http://us2.php.net/static The manual isn't all that clear, but the user comments help a lot (which, I have found, is often the case, but that's a rant for another day... At least we have a manual that accepts such comments!) class Singleton { function getFoo() { $object = Singleton::getFooRef(); if (!is_a('Foo', $object)) { $object = new Foo(); } return $object; } function getFooRef() { static $object = null; return $object; } } $myFoo = Singleton::getFoo(); Hope that helps. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Templates, PHP Frameworks, and DB Abstraction?
Finally, does anyone have any suggestions for a good PHP database abstraction library? PHP5 has PDO for database abstraction; check the manual for information on that one. If you're stuck with PHP4 then PEAR has several offerings: http://pear.php.net/package/DB/ http://pear.php.net/package/MDB2/ I've used PEAR DB and never had problems with it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Update site through email
Hello, At my last job there were several companies that would send us text invoices by email. These email accounts were on a Linux box, and when the mail would come in the message was sent to scripts via STDIN. I'm not sure HOW it was done but I know that it CAN be done. I would be concerned about security in this case. The From: header can be spoofed, as can any other header, so before you do this make sure you have some kind of authentication scheme. Wouldn't want some lamer finding the email address and spamming it with v14gr4 email. -K.Bear Hy guys I'd like to know if there is a way to update a site through sending an email. Something like this, you send an email and the body of the email substitutes a text you use in your site. Igreat apreciate any help since I couldn't find anything on this topic. Thanks, doRodrigo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Re: creating a threaded message system--sorting messages
Sounds like that darn Hierarchial Data again. Give this a read and see if it helps you out at all. In particular, you may find the area 'Finding the Depth of the Nodes' helpful. http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Hope it helps, -K.Bear -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: creating a threaded message system--sorting messages
Hello, As Adam pointed out, this can be deadly to your database, especially as the number of posts grows. If you want to go that route, I would recommend selecting all the posts in that particular thread and sorting the data out in PHP somehow. No need to slam your database with (potentially) hundreds of queries to display a discussion. Multiply that by several page views at once... If you don't mind the extra work and investigation, I would recommend downloading some PHP forum software that supports threaded discussion and see how they implement it. I found several listed in DMOZ: http://dmoz.org/Computers/Programming/Languages/PHP/Scripts/Forums/ Let us know what you come up with! I'd like to see how you work this out. This is a good computer science type of problem with practical application - the kind of stuff they should have taught me in school but never did. ~(o: Best of luck, -K.Bear SOLVED, almost. I read the article suggested by K.Bear and found the recommended solution to be a bit more complicated than I wanted to implement. I then found another way to do this using the existing Adjacency List Model through a recursive function. So basically, you query the database for the post_id of the very first post in the discussion. You then call a function that displays that post, searches for all children of that post and then calls itself recursively on each of the children it discovers. This works great for spitting out the posts in the proper order. Now I'm trying to figure out how to make sure the indenting looks right in the browser. - Ben Wouldn't that involve a separate SQL query for every post? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Question about constructors and destructors
For all to know This bug is linux AND windows, the problem is caused when you have the zend.ze1_compatibility_mode = On in the php.ini file. This is a bug that was reported before several times without having been resolved. I commented and reactiveated the bug on the php bug submission engine... That actually makes total sense and might not be a bug. Okay, I know, it's weird behavior, but: $mytest = new test(); Has different behavior in PHP4 than in PHP5. In PHP4, the test() object is created; Then, because = is used, a copy of that object is assigned to $mytest. The original copy of the object is then destroyed at that point. This is why, in PHP4, you often see $mytest = new test(); Which assigns by reference. Since PHP4 compatibility was enabled, there were two copies of the object, and when the original copy went out of scope the destructor was called. PHP5 has a totally different way of handling this; If I understand correctly, it works similarly to Java, in that you pass around handles to the object instead of the object itself. So, $mytest = new test(); In PHP5 only creates one copy of the object, and $mytest is a handle to that object. This can be very confusing behavior, and I wish that it was more explicit in the manual... -K. Bear -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Better way of doing this? (menu and submenus)
Hello, There is an EXCELLENT article at MySQL.com that talks about storing hierarchal data, which is exactly what you want to do. The theory is not MySQL specific, so you can apply it to any database system. It covers two techniques, one of which Philip Thompson covered, and another that I prefer. Well written and a recommended read for everyone. http://dev.mysql.com/tech-resources/articles/hierarchical-data.html -K. Bear -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Word file to PDF
Hello Kevin, You might want to try this: Run PHP on a windows platform that has MSWord and the PDF printing libraries installed. Use PHP's COM support to load an MSWord object and see if you can get it to load the word document and print it out as a PDF file. Once it is printed to the file, you can use PHP to read the file and do whatever is needed from here. I've never tried it with PHP, but with experimentation and research you should be able to make it work. I know that where I work we convert MS Word, Excel, and other kinds of documents to PDFs automatically using this method, though I think the appliaction than controls everything is written in C. Parsing and MSWord file manually with images et al, then reliably converting it to a PDF document... Yikes, if anyone can do this, you're my god. Best of luck, let us know what solution you come up with. -KBear Original Message: Hi there, How can I convert a Word file (*.doc) to PDF file? Are there any libraries available? Can you give me some hint how can I do that? Thanks. Kevin. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic/runtime object creation
Hello Joe, If you are careful, you can build a string of PHP and eval() it to create a new class definition. I've done this before, but it was for the novelty more than needed to actually use it. I know for a fact that I have seen several projects for this on the web; However, I tried doing a quick search and I was unable to find anything. Figures. do: Anyways, yes it is possible and people have done it before, but if I were going down this path I would second guess myself as to if this was the best solution. You should be able to get by with something simpler (and less time consuming to develop and test). I recommend finding a different solution, but if this is what _you_ need to do then who am I to tell you no? Best of luck! -KBear Original Message Below: Hi, forgive me if this is a complete noob question What i want to do is create an object at runtime with members and methods based on the result of queries from my db back end. is this (a) possible? or (b) something i should get out of my head and go and find a better solution? basically is their a create_object() style function, and some add_method() / add_member() style functions, that to allow me to instance things dynamically at runtime. sorry that i am not being to clear, but i hope you can get my gist, thanks in advance to any help any of you can give me! cheers joe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] The length of midi
You may find this to be useful: http://www.google.com/search?hl=enq=PHP+MIDI -KBear Original Message Follows: Hi, Does anybody know how to determine the length (in seconds) of midi melody? -- s pozdravem Bronislav Klucka --=[ pro2-soft.com ]=-- http://pro2-soft.com [EMAIL PROTECTED] +420 605 58 29 22 * webove aplikace * software na zakazku --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP4: Using create_function to create an object method
Hello all, I was playing with create_function the other day and found that it is not possible to use create_function to create a method for an object. Code example: ?php $test = create_function( '', 'echo Testing;' ); $test(); // will work $t = 'test'; ${$t}(); // will work $o = new stdClass(); $o-test = create_function( '', 'echo Testing;' ); $o-test(); // Will break: // Fatal error: Call to undefined function: test() // in /www/devel/jmiller/include/test.php on line 10 ? I saw several work arounds for this in the comments section of the PHP manual, but I did not see anything in the manual that explicitly states that this will not work. On an intuitive level, it would seem to me that it would and should. Using call_user_func( $o-test ) does work. I did some google searching but I didn't come up with anything that seemed relevant. Could someone point me to some documentation that explains why $o-test() does not work? It would seem to me that this would be a useful feature for dynamically building objects for use in SOAP, for example, without having to eval() a big block of code. From what I understand, in PHP5 there is a magical __call() method for all classes/objects, but in PHP4 this capability does not exist. No, I'm not actually trying to play with this in any serious manner, nor do I intend to write 'real' code that uses this... Just a curiousity and something to play around with. (o: Thank you, all. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP parse Excel and Access files
There does appear to be a PEAR-based Excel reader located at: http://devel.akbkhome.com/svn/index.php/akpear/Spreadsheet_Excel_Reader/ However, I have not used it and cannot comment on its functionality. Good luck! -KBear Kioto wrote: How to read and get data from Excel Files and Access Files. Can you post me articles and tutorials on the web-sites that explain the basic concept to create an interface for PHP and this files-type. Thanks so much to all. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php