PHP4 to PHP5 Migration What are some good steps to follow for a smooth migration from PHP4 to PHP5. What are some types of code that are likely to break? Solution : I also once worked on an app which used PHP4's XML support quite heavily, and would have required quite a bit of work to move to PHP5. One of the other significant changes I was looking at at the time was the change of the default handling of function parameters. In
undefined
PHP array indexing: $array[$index] vs $array[“$index”] vs $array[“{$index}”] What is the difference, if any, between these methods of indexing into a PHP array: $array[$index] $array["$index"] $array["{$index}"] I'm interested in both the performance and functional differences. Update: I'm not sure that's right. I ran this code: $array = array(100, 200, 300); print_r($array); $idx = 0; $array[$idx] = 123; print_r($array); $array["$idx"] = 456; print_r($array); $array["{$idx}"] = 789; print_r($array); And got this output: Array ( [0] => 100 [1] => 200 [2] => 300 ) Array
undefined
Login Script with hidden buttons I have been using PHP and Javascript for building my dads website. He wants to incorporate a login system into his website. I have the design for the login system using PHP, my problem is how do I show buttons if the person is logged in. For Example - You have Home, Products, About Us, and Contact. Well I want to have buttons for Dealer, Distributor, and maybe other information if the user is logged in. So I will have Home, Products, About
undefined
MySQL/Apache Error in PHP MySQL query I am getting the following error: Access denied for user 'apache'@'localhost' (using password: NO) When using the following code: <?php include("../includes/connect.php"); $query = "SELECT * from story"; $result = mysql_query($query) or die(mysql_error()); echo "<h1>Delete Story</h1>"; if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_row($result)){ echo '<b>'.$row[1].'</b><span align="right"><a href="../process/delete_story.php?id='.$row[0].'">Delete</a></span>'; echo '<br /><i>'.$row[2].'</i>'; } } else { echo "No stories available."; } ?> The connect.php file contains my MySQL connect calls that are working fine with my INSERT queries in
undefined
How to include PHP files that require an absolute path? I have a directory structure like the following; script.php inc/include1.phpinc/include2.php objects/object1.phpobjects/object2.php soap/soap.php Now, I use those objects in both script.php and /soap/soap.php, I could move them, but I want the directory structure like that for a specific reason. When executing script.php the include path is inc/include.php and when executing /soap/soap.php it's ../inc, absolute paths work, /mnt/webdev/[project name]/inc/include1.php... But it's an ugly solution if I ever want to move the directory to a different location. So is there a way to use relative paths, or a
undefined
PHP: show a number to 2 decimal places What's the correct way to round a PHP string to 2 decimal places? $number = "520"; // It's a string from a DB $formatted_number = round_to_2dp($number); echo $formatted_number; Output is "520.00"; How function round_to_2dp() definition should be? Best Answer : can use number_format(): return number_format((float)$number, 2, '.', ''); Example: $foo = "105"; echo number_format((float)$foo, 2, '.', ''); // Outputs -> 105.00 This function returns a string.
undefined
PHP file_get_contents() returns “failed to open stream: HTTP request failed!” Problem : I am having problems calling a url from PHP code. I need to call a service using a query string from my PHP code. If I type the url into a browser, it works ok, but if I use file-get-contents() to make the call, I get: Warning: file-get-contents(http://.... ) failed to open stream: HTTP request failed! HTTP/1.1 202 Accepted in ... The code I am using is: $query=file_get_contents('http://###.##.##.##/mp/get?mpsrc=http://mybucket.s3.amazonaws.com/11111.mpg&mpaction=convert format=flv'); echo($query); Like