php

Is there a way to set a different PHP module per Virtual Host?

I'm developing for a bunch of sites on my local machine. Some of those sites ultimately run on php5.3, and some run on php5.2. Is there a way I can setup virtual hosts to use different versions of php for each? ...

Preg_match help for finding count

HI all i have a string <font size="+1"><b>Open Directory Sites</b></font> (1-20 of 10000)<p> i need to get 10000 as answer .. how i use preg_match ??? Note: this is implortant that the multiple occurance of match Thanks in advance ...

[PHP] Array key as string and number

How to make arrays in which the key is number and string. <?php $array = array ( 'test' => 'thing', 'blah' => 'things' ); echo $array[0]; // thing echo $array[1]; // things echo $array['test']; // thing echo $array['blah']; // things ?> ...

Login/Authorization best practices in a PHP MVC environment

I am working with a homebuilt MVC-oriented framework, and need to implement a login page. At the moment, the way it works is each controller that needs authorization calls its authorize() method, which in pseudo-code looks like: protected function authorize() { if (logged in) { return true; } if (login form submitte...

PHP: How to set a variable in the caller scope, like the extract() function

I know that directly setting a variable in the scope of caller is probably not a good idea. However, the PHP extract() function does exactly that! I would like to write my over version of extract() but cannot figure out how to actually go about setting the variables in the caller. Any ideas? The closest I have come is modifying the calle...

eclipse for php: why syntax coloring go crazy?

see screen capture: OS: win. Eclipse and PDT: latest stable. Rebooting no take effect. ...

TCPDF outputs weird characters in IE8

Today I started experimenting with PHP-based PDF generators. I tried TCPDF and it works fine for the most part, although it seems to be a little slow. But when I load the PHP file that generates my PDF in Internet Explorer 8, I see lines and lines of weird characters. Chrome however recognizes it as a PDF. I'm assuming that I have to se...

What is the difference between realpath() and is_dir() in php?

What is the difference between realpath($path) and is_dir($path)? I know realpath follows symbolic links, but is there a performance difference between the two? ...

PHP: Is this safe for providing JSONP?

<?php header('content-type: application/json'); $json = json_encode($data); echo isset($_GET['callback']) ? "{$_GET['callback']}($json)" : $json; Or should I for example filter the $_GET['callback'] variable so that it only contains a valid JavaScript function name? If so, what are valid JavaScript function names? Or is not ...

$facebook->getSession(); not working. No idea why?

<?php require 'facebook.php'; // Create our Application instance. $facebook = new Facebook(array( 'appId' => '130407366991766', 'secret' => 'f692cb73889096ca0835a55bc0a82c34', 'cookie' => true, )); // We may or may not have this data based on a $_GET or $_COOKIE based session. // // If we get a session here, it means we found ...

Multiple WHERE with LIMIT MySQL

Using PHP, is it possible to select multiple rows from one table, in a MySQL database, with different WHERE clauses having a specific LIMIT for each WHERE clause. For example: SELECT * FROM the_table WHERE color = 'blue' LIMIT 5 OR color = 'red' LIMIT 10 I know the above statement does not work. But is there a way to do this with a s...

Wordpress function returns white screen in plugin

I am brand new at writing Wordpress plugins, so to start I am trying to create a simple one that just modifies a string. I wrote the script a while ago, and know that it functions. But to use it for Wordpress I want to apply it to the post titles. When I replaced the string with the function "get_the_title()" it returns a white screen. I...

ONE question regular expression PHP

Count character '_' in start line example : subject = '_abcd_abc'; // return 1 or subject = '__abcd_abc'; // return 2 or subject = '___abcd_abc'; // return 3 everyone help me ~ I use PHP ...

Cakephp, ordering associated tables.

Hi, When I search a model which "has many" of something else. For example a blog post has many categories. When searching for blog post with categories associated, how do I order the associated categories? When the array is returned it ignores the order on the category model and defaults to it's usual id order. Cheers. ...

Weird behavior of mysqli->query for multiple DELETE

I am running following query by using mysqli->query but despite of showing affected rows removing correct records,MYSQL is not removing the records. The same query runs perfect on command line. DELETE m,s FROM t1 m LEFT JOIN t2 s ON t1.sbid = t2.sb_message_id WHERE m.sbuid = 11 mysqli->affected_rows gives correct count but its weird t...

unreadable output with var_dump on xampp windows

Hello I'm having some issue with var_dump.i'm using xampp 1.7.3 on windows. I think in previous version i could output a variable with var_dump without print "<pre>" print "</pre>" firebug is not installed on my firefox and i'm not using xdebug. Formally i have even red colored and nicely formatted output.Now it's completly unre...

Time difference between unix timestamps

Hi, I have to try and work out if a unix timestamp is between 21 days and 49 days from the current date. Can anyone help me to work this out? Thanks! ...

Content Displaying all at once PHP

Hey, well I don't really know how to describe this but here's my current situation. On my old host, I could have a loop going and echo things in the loop. As the code was running that loop, the text i was echoing would appear right away and I could see things happening. Now though, on my current host if I have a loop like that I only s...

Javascript window.open Calling Twice

I'm using this code in a php conditional if/else statement to open a new window. echo("<script type=\"text/javascript\"> <!-- window.open(\"http://www.example.com/index.php?$var\"); //--> </script> "); It's opening 2 windows instead of one, but only on my live site (on a dedicated server) and not on the test site (shared server). EDI...

Different ORDER BY for each SELECT in a UNION with MySQL

Using PHP and MySQL, is there a way to use a different ORDER BY for each of the SELECT statements in a UNION? SELECT * FROM the_table WHERE color = 'blue' ORDER BY price ASC LIMIT 5 UNION ALL SELECT * FROM the_table WHERE color = 'red' ORDER BY RAND() LIMIT 10 The above statement does not work. It seems you can only do an ORDER BY on ...