php

preg_replace inside of preg_match_all problems

I'm trying to find some certain blocks in my data file and replace something inside of them. After that put the whole thing (with replaced data) into a new file. My code at the moment looks like this: $content = file_get_contents('file.ext', true); //find certain pattern blocks first preg_match_all('/regexp/su', $content, $matches); f...

require_once(../../path/to/script.php) failed to open stream permission denied

See an example here: http://mattpotts.com/portal/ I put an includeme.htm in each directory on the required path to find the point of failure. It works fine on my local machine (windows) with the same directory structure but fails on my remote (linux) server. Directory structure: +-firefli/ drwx--x--x +-private_html/ ...

Export a variable from PHP to shell

I'm trying to set a variable that should be accessible from outside PHP. Ideally this should be a local variable, but environment variables are also welcome. First, I've tried putenv(), but this gives no result: $ php -r "putenv('PHP_TEST=string');" ; echo $PHP_TEST $ When i call getenv() from the same script — it results in ...

Write back to an XML file

I was wondering if this is possible, I'm not looking for code, i just want to be pointed in the right direction - php, asp or javascript. I have an xml file: <?xml version="1.0" encoding="utf-8"?> <Groups> <Group> <groupNum></groupNum> <purgeGroup></purgeGroup> <DupeRecs> <DupeRec> ...

PHP Transparent Image Layering Problems

I just can't tell why this: <?php $image = imagecreatefromjpeg($_GET['u']); imagealphablending($image, true); imagesavealpha($image,true); $overlay = imagecreatefrompng("overlay.png"); imagealphablending($overlay, true); imagesavealpha($overlay,true); $finalImage = imagecreate(85,85); imagealphab...

PHP: Using spaces in associative array indices

Is this bad practice/can cause problems? $_SESSION['stuff to keep'] As opposed to calling str_replace() on the indices. ...

if isset statement with javascript ?

În php I would use this to see if a variable is set and then use that value, otherwise make it a zero: $pic_action = isset($_POST['pic_action']) ? $_POST['pic_action'] : 0; But what is the equivalent in javascript? I want to check if an element exists in the document, and then if it does, add it to the variable, otherwise add som...

PHP array_multisort does not sort properly while using complex array

I've got an multidimensional array like this: Array ( [thursday] => Array ( [0] => Array ( [title] => Movie2 [time] => 15.30 [venue] => VenueA ) [1] => Array ( [title] => Mo...

Good examples of sites built with PHP on server side and GWT on client side?

All the time, I use PHP on server side to generate HTML/XHTML directly or via Smarty/PHPTAL or any other templating engine. I do believe most of developers follow the same path most of the time. Now I'm thinking of delegating GUI & client-side to GWT and using to send RPCXML / RPCJSON / POST / GET to server side which run PHP. I'm looki...

Basic PHP MySQL array grouping question

Quick question, which I think has a very easy solution for someone who has anything above the most rudimentary knowledge of PHP/MySQL as I do. I have a list of cities in a variety of states stored in a database with city, state and some other variables. Right now they get pulled as a list sorted by city name: Anchorage, AK Baltimore, ...

What differences do I have to take into account if using MySQL Transactions?

I was recently told that I should use transactions in my application as they can help run code quicker and prevent MySQL code from executing before a whole page has loaded (e.g. if someone is just refreshing on my page and the whole page doesn't load, no MySQL calls will start and it reduces load on the server.) I'm wondering if I wante...

split text into batches with line breaks

I hope somebody with better problem solving skills can help me out here. I have a textarea and all I had to do is split the text into 50 chars and feed the lines to another app. No problem. But I forgot about \n line breaks. If someone puts linebreak I have to also make that a seperate line. Here's my current code ($content is the origin...

JQuery and PHP rate me script?

I found this rating script on [http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery#Rate_me:_Using_Ajax] and I cant seem to get it to work like in the example on http://jquery.bassistance.de/example-rateme.html when I click the rating nothing happens. How can I fix this problem? Here is the complete script below. <!DOCTYPE...

PHP function to return a reference a variable

I'm trying to write a function that will return a reference to a PDO object. The reason for wanting a reference is if, for some reason, the PDO object gets called twice in one page load, it will just return the same object rather than initializing a new one. This isn't silly, is it? :/ function &getPDO() { var $pdo; if (!$pdo) ...

Help loading contstants stored in serialized array using eval() and constant()

DISCLAIMER: Please read carefully as this is NOT a question about storing arrays in constants or simple eval() or serialize() techniques. This IS a question primarily about how constants work in PHP and why the constant() function is not working to convert a constant name into a constant value. Thanks. BACKGROUND: For various reasons, I...

Is it fine with PHP to assign NULL here?

Example: public function prepare($sql, &$p = NULL) { p is assigned by reference. I'm not sure if I can assign safely NULL here as default. Is that ok in this case? ...

PHP wordpress style related posts

Do you know how wordpress decides which related posts to show?I mean I know if it has tags, then it's easy but if it doesn't? Best Regards, ...

Will this foreach copy the values in memory?

Example: foreach ($veryFatArray as $key => $value) { Will the foreach assign the value behind the $key by reference to $value, or will $value be a copy of what's stored in the array? And if yes, how could I get an reference only? The array values store pretty big amounts of data so copying them is not really good. ...

Order a mysql query alphabetically

Let's say that I have the following code: SELECT * FROM table where company LIKE '%Auto%' And I receive more results, and I want to have an option to sort the results alphabetically, let's say that the user wants to sort the search results for the ones which start with "C"! Best Regards, ...

Is there a reversed function for mysql_escape_string?

So that I can change string like I\'ll go back to I'll go ...