php

Weird libcurl error in PHP (Failed to connect to IPHERE: Unknown error 22)

Hi, I was finishing my script and suddenly libcurl stopped working. I thought the server I was connecting to was down or something, but invariably of where I try to connect I get the same sucky error. I even tried rebooting my box, same results. The code snippet where things happen is: public function navigate(array $data) { ...

PHP: thumb-rules for sessions

I had to break my too complex project, about 100files, to small files. A problem is that it is still hard to see the logic, getting nice heap of session errors: `Cannot send session cookie - headers already sent by` How do you manage your session commands, such as "session-start" and "ob-end-flush"? Do you add them to the beginning an...

How to Implement URL Routing with PHP + IIS?

I wrote a content switcher script that uses dynamic URLs to pass parameters indicating what data is to be sent. For example to view the about page you would type: http://www.example.com/?page=about The issue is that this is not user friendly especially in my case where users will not necessarily be accessing this page via a link from t...

Automatic decimal number formatting in SQL or PHP?

In my DB, most numeric values are of type DECIMAL(10,6). They are currency columns. Now, when I retrieve the numbers from mysql, I get something like this 34.123456 //I want these 0.987654 500.000000 //I do not want these 1.000000 Is it possible to have the numbers automatically show up as integers when they are and to maintain deci...

How to log out users using Facebook Connect in PHP and Zend?

I am trying to build a Connect app using PHP and Zend Framework. I also have a Zend_Auth based user authentication system. Now, I am able to log in using Facebook but log out is not working. I need to clear the Zend_Auth identity as well as remove all Facebook login info as well. What would be the best way to do this? I tried facebook_...

Why use sprintf function in PHP?

I am trying to learn more about the PHP function sprintf() but php.net did not help me much as I am still cofused, why would you want to use it? Take a look at my example below... Why use this... $output = sprintf("Here is the result: %s for this date %s", $result, $date); When this does the same and is easiar IMO to write... ...

PHP echo vs PHP short tags

Are they equal in safeness? I was informed that using <?=$function_here?> was less safe, and that it slows down page load. So I am now strictly biased to using echo. I just wanted to know the advantages/disadvantages, or are they pretty much the same. ...

difference of date in sql and php

how can calculate (now) - (date in database) ...

How do I use a variable pattern with preg_match?

I don't know if this is enough data to feed off of, but I have preg_match('/SAMPLETEXT/', $bcurl, $cookie1); and I was wondering if I can make it preg_match($newfunction, $bcurl, $cookie1); but when I do, I get this error "Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in". How ...

How to send multiple messages with xmpphp

As the title says, i want to send the same message to multiple recipients. I use the PHP library XMPPHP and send single messages with this: <?php include("xmpp.php"); $conn = new XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp', 'gmail.com', $printlog=False, $loglevel=LOGGING_INFO); $conn->connect(); $conn->processUntil('s...

Regular Expression Works In One Script and Doesn't In Another

I've stumbled across an interesting bug in PHP. Basically I have a regular expression seen below which works fine in one script (Script A) but fails to work when put into a class and used in a script (Script B). I have tested this script on PHP 5.3, and 5.2. Script A: http://iamdb.googlecode.com/svn/trunk/testing.php Script B: Class ...

Increase PHP Memory limit (Apache, Drupal6)

I'm trying to run a Drupal installation on a shared hosting server. (I'm just subscribing to a provider - I don't own the box.) I need to increase the PHP memory limit for my Apache server. I have tried ini_set('memory_limit', '64M'); in settings.php (a file that is included in every request), but this causes Internal Server Error 50...

Escaping special characters in JavaScript

Hello all. I need a method in JavaScript to escape all characters which are not ( a-z / A-Z / 0-9 / - / _ ) If the character is ø it should be replaced with oe, if it's å then replaced with aa, and more.... if characters are not on the list, they should be replaced with an underscore. If there are 2 underscores in a row ( __ ) they sh...

phpdoc standard for setting default value of an optional parameter?

Example: /** * This function will determine whether or not one string starts with another string. * @param string $haystack <p>The string that needs to be checked.</p> * @param string $needle <p>The string that is being checked for.</p> * @param boolean $case[optional] <p>Set to false to ignore case(capital or normal characters)</p>...

Adding an If/else error/success message to PHP MYSQL function

Im wondering how i could add a success or fail message to return at the end of this function function InsertIntoDB($field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8, $field9){ $sql = "INSERT INTO `caches` ( `url` , `username` , `password` , `cachename` , `lat` , `long` , `message` , `notes` , `tags` ) VALUE...

How do i get wp nonce value for my php libcurl script

I'd like to automate some administrative task for myself on my wpmu install. For example, I'm trying to write php curl script for logging in and adding a new blog. So i'm already logged in via curl and now i want to post form that's in wpmu-blogs.php but it has hidden wp nonce field. How do i get this value into variable? I checked sourc...

PHP: SeekableIterator::seek()

If I want to implement seek() to complete the SeekableIterator interface, should I internally revert to the old position if the seeked position is invalid? Like this: public function seek( $position ) { $oldPosition = $this->_position; $this->_position = $position; if( !$this->valid() ) { $this->_position = $oldP...

How can I abstract mysqli prepared statements in PHP?

I'm using my own class for database queries, extending mysqli: class iDatabase extends mysqli { public $errorMsg; private $totalQueries; private $stmt; public function __construct() { parent::__construct( 'localhost', 'asd', 'asd', 'asd' ); if ( mysqli_connect_errno() ) { $this->errorMsg = 'Could not connect to server.<...

PHP: Concatenate array element into string with ',' as the separator

Is there a quick way ( existing method) Concatenate array element into string with ',' as the separator? Specifically I am looking for a single line of method replacing the following routine: //given ('a','b','c'), it will return 'a,b,c' private static function ConstructArrayConcantenate($groupViewID) { $groupIDStr=''; foreach (...

Best method for converting a PHP array to javascript

I am passing a PHP array to a javascript function. The only way I know to do this is to create a js array from the PHP array and pass that to the js function. But this creates a huge chunk of code to transfer (see code below - there's a lot more but I'm sure you get the general idea). I suspect that there is a more efficient method. Woul...