php

How do I export to CSV file with table record value with comma in it properly?

I have a function that exports values into a CSV file, but the "comments" field has commas in it and it messes up the columns when you open it in a spreadsheet program. Is there a way around exporting it properly? //this exports only names and comments into a CSV file function exportNamesCommentsCSV($table, $columns) { $file = "vol...

accessing php arrays with explicit strings as index

I know that it's more performant to use '' delimited strings rather than ""... but I was wondering if there's any performance improvemente doing this $a = array( 'table' => 'myTable', 'order' => 'myOrder' ); $table = $a['table'] instead of $a = array( table => 'myTable', order => 'myOrder' ); $table = $a[table] I guess so, bu...

Can I include CURL library in my PHP script as a class

I want to use CURL library but I don't want to install it in a hard way I just want to do something like this require_once('curl.php'); I am not sure if this possible or not? and where can I found this CURL class? thanks ...

How do I insert into non-default Google Calendar using Zend / PHP

I'm trying to insert a new event into Google Calendar, which I can do fine by the following: $sname = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar $client = Zend_Gdata_ClientLogin::getHttpClient($userName,$password,$sname); $service = new Zend_Gdata_Calendar($client); $event = $service->newEventEntry(...

file_get_contents VS CURL, what has better performance?

I am using PHP to build a web crawler to crawl millions of URLs, what is better for me in terms of performance? file_get_contents or CURL? Thanks. ...

Displaying images using PHP not working

I'm trying to display an image using a PHP script. Basically so the php script is passed on the full path to the image, and it then displays that image in the browser. I've checked to make sure the image exists, it is being read correctly, etc, however in the browser i just see the broken image box (e.g the small red cross in IE) if I go...

Switch to Java from PHP/Ajax in 45 days (or so)

Because of the nature of new project we are about to start, I need to get into Java world rather quickly. I have about 8 years of PHP experience, and about 3 year in Javascript. (CI, Kohana and my own MVC framework) I have solid knowledge of OOP (as much as you can get from PHP/JS and little ActionScript & python here and there) So i...

How to find a string in an array in PHP?

Lets assume I have an array in PHP: $array = array("apple", "banana", "cap", "dog", etc..) up to 80 values. and a string variable: $str = "abc"; If I want to check whether this string ($str) is exists in the array or not, I use preg_match function. Which is like this: $isExists = preg_match("/$str/", $array); if ($isExists){ ...

Extracting details from a database timestamp

Hi, I'm learning about timestamps. I can find lots of infomation about extracting data from current timestamps but little about querying a database timestamp. For example, I'd like to perform the following (the syntax is not correct, but should hopefully illustrate my question) SELECT * FROM database where timestamp DAY('12') AND MONTH...

How best to display a stock file dynamicallly?

I'm working on a website for a client, in PHP/MySQL. They are a publisher, and the site needs to show whether the book you are looking at is in stock with their distributor. The stock file is a CSV file on the distributor's FTP. This file is updated at a certain time every evening. So far I've written a script in PHP that copies the con...

Is there a way to emulate the 'whois' tool using php?

I don't have whois installed on my server (apparently it's in the works but no real news on it). I was wondering if anybody knew a way to emulate the functionality of it though. I figured I'd be posting some data to a url but I don't know what, or where. Basically I'm at a complete loss, and would appreciate any help or even something t...

PHP Time after midnight problem

I have an array of times I want to print out. I want the times that have passed lets say 12:00 clock to be 'greyed out'. $theTime = '12:00'; if($theTime >= $time[$i]) {....} 02:30 03:50 03:20 04:50 05:45 19:45 20:00 20:50 20:55 21:25 21:30 22:00 22:45 23:55 00:50 00:55 Im doing a simple compare 12:00 a clock to each value. The p...

quotation marks etc

Is there any different typing: <?php echo $_SERVER[REQUEST_URI] ?> and <?php echo $_SERVER['REQUEST_URI'] ?> and last <?php echo $_SERVER["REQUEST_URI"] ?>? Them all work... I use the first one. Maybe one is faster than the other? Thanks A Noob ...

Exceptions in PHP - Try/Catch or set_exception_handler?

I'm developing some lower end code in my system that uses multiple child classes of the php exception class. Essentially I have the exceptions broken up to a few categories. What I'm wanting to do is two things. I need all exceptions that are fired in the application to be handled in a single place. I need to be able to log and the...

Javascript Not Firing after Dir Reorganization

Ok, so here's the situation. I'm working on a site that allows people to upload things to a database that are then pulled to the frontpage so people can see them. It is a pretty straightforward site and I had it working real well but i was developing everything at ../html/backend for the sake of simplicity and to make sure nothing was s...

Change the characters in mysql with Convert failing - Still getting Não

Hey! I am populating this mysql table with data from a php (via post and using filter_input). The database is utf8 but when I have a user that inputs words with ^,',',~ like Não I get this -> Não What do I have to do to make it show the correct values. Or should I try to make some correction when I retrieve the data?? UPDATE: I hav...

How to join strings in PHP?

I have three strings: $str1 = "abc"; $str2 = "def"; $str3 = "ghi"; I can get the value of all of them like this: echo "$str1$str2$str3"; But I heard there is a way to join them together, so I can echo all of them without quotes. ...

Get PHP assoc array key in loop

I have the following code: while ($row = mysql_fetch_array($result, MYSQL_NUM)) { for ($i=0; $i<count($row); $i++) { (DO THING HERE) $row[$i] = str_replace("\n", " ", $row[$i]); $row[$i] = str_replace("\r", " ", $row[$i]); } } I basically want to do, if the associative array key is equal to "email" (so $row...

How to check real names and surnames - PHP

Hi everybody, here's my problem: I want to check if a user insert a real name and surname by checking if they have only letters (of any alphabet) and ' or - in PHP. I've found a solution here (but I don't remember the link) on how to check if a string has only letters: preg_match('/^[\p{L} ]+$/u',$name) but I'd like to admit ' and - t...

PHP extension on a Mac

I wrote a PHP extension, and I'm trying to get it running on Mac's Apache server. It runs fine via the command line, for example: $ php -r 'dl("mylib.dylib"); I also tried building Apache from source, and it works perfectly when I run that (I set it up to use the same PHP as Mac's built-in Apache, too, so no difference there). How...