php

Help with consuming JSON feed with PHP & json_decode

Hello there! I've having an issue with consuming a particular feed for a client. They have given me a remote URL and the response is a JSON string like so: {"affiliate": [ {"ID":"1", "COUNTRY":"EXAMPLE", "NETWORK":"EXAMPLE", "PRIMARY":"EXAMPLE"}, {"ID":"2", "EXAMPLE":"EXAMPLE", "COUNTRY":"EXAMPLE", "NETWORK":"EXAMPLE", "PRIMARY":"EXAMPL...

PHP writing large amounts of files to one directory

I'm using PHP to make a simple caching system, but I'm going to be caching up to 10,000 files in one run of the script. At the moment I'm using a simple loop with $file = "../cache/".$id.".htm"; $handle = fopen($file, 'w'); fwrite($handle, $temp); fclose($handle); ($id being a random string which is assigned to a row in a database) b...

PHP - Merge two arrays (same-length) into one associative?

Hi, pretty straightforward question actually.. is it possible in PHP to combine two separate arrays of the same length to one associative array where the values of the first array are used as keys in the associative array? I could ofcourse do this, but I'm looking for another (built-in) function, or more efficient solution..? fun...

Wordpress PHP Image change depending on a language

I am trying to write a piece of code that would allow me to change images or a whole block of a div depending on the language <?php if($_SESSION['lang'] == "fr"){ echo "images/header-fr-4.jpg"; }else{ echo "images/header-4-en.jpg"; } ?> Is there any other way of doing this in wordpress? ...

Wordpress mod_rewrite is stopping my query string from working!

In my root .htaccess file wordpress has put this: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress and in a sub directory I have a .htaccess file that says: RewriteEngine on Rewrit...

Question about mysql_real_escape_string and single quote

Hey everyone, I'm quite frustrated. I want to be able to insert into my database names with single quotes - for example, O'Connor. So, when inserting into the DB, I do: $lname = mysql_real_escape_string($_POST['lname']); And then I insert $lname into the DB. When it's in the DB, it appears as O\'Connor. So, if I were to recall th...

PHP showing output of foreach to screen, for each item

One thing I have noticed with php, is that nothing is output to the screen until the script has stopped working. For the project I am working on I feed in a list of over 100 items and it performs a HTTP request for each item and when finished, shows a page with the status of each item, success failure etc. What I want to know is if ther...

PHP Getting Domain Name From Subdomain

I need to write a function to parse variables which contain domain names. It's best I explain this with an example, the variable could contain any of these things: here.example.com example.com example.org here.example.org But when passed through my function all of these must return either example.com or example.co.uk, the root domain ...

How Secure is this MySQL statement in a PHP script?

How secure is this MySQL statement built in a PHP? Would it be vulnerable to an SQL injection? $sql = sprintf("INSERT IGNORE INTO my_table VALUES(%d, %d, 1, NOW())", mysql_escape_string($_SESSION['client']['id']), mysql_escape_string($_POST['id'])); ...

How can I have wordpress print posts whose IDs appear in an array?

I have an array of post IDs contained in $postarray. I would like to print the posts corresponding to these IDs in Wordpress. The code I am using is as follows: query_posts(array('post__in' => $postarray)); if (have_posts()) : while (have_posts()) : the_post(); the_title(); the_excerpt(); endwhile; endif; Desp...

Update Multiple Rows Mysql from php

Hi all, Here's what I'm trying to do: Update an arbitrary number of rows, changing several fields to the SAME value. $var = "1 3 5 7 9"; $query = "UPDATE tablename SET seen_before = 1 WHERE id = SET ($var);" My question is this: What is the exact syntax on the Where clause when I lookin in a set, and how do I pass in the Set ite...

php syntax issue?

value="<?=$file_source?>"> it will show the >"> at my browser but if value="<?php echo $file_source?>"> it will show correctly in browser. Is it due to php versioning? Also I realize some php classes written by others (which I download online), doesn't use <?php ?> , it directly use <? ?> But when I run it locally at xampp, I n...

Disply php errors when using Zend framework

Hey SO folk, I've been using Zend Framework and just living with this problem for a while, but it's now just gotten too annoying so i'll send the question out to you. There are certain problems within the Zend framework that Zend can recognize (such as calling a nonexistent controller), and will send that problem to the ErrorController...

Parsing Custom Tags with PHP

I am trying to make simple custom tags to allow custom templates on my app. But I can't figure out how to parse and replace the tags. (example) <div class="blog"> <module display="posts" limit="10" show="excerpt" /> </div> <div class="sidebar"> <module display="users" limit="5" /> <module display="comment" limit="10" /> </div> for e...

Use PHP to convert PNG to JPG with compression?

I have a bunch of high quality PNG files. I want to use PHP to convert them to JPG because of it's smaller file sizes while maintaining quality. I want to display the JPG files on the web. Does PHP have functions/libraries to do this? Is the quality/compression any good? ...

php echo acting strange

hi All this is probably so simple but still i can't get it to work i'm using this statement: echo "$num1"."+"."$num2"."=".$num1+$num2."<BR>"; i was expecting something like 3+3=6 but instead i get just 6 any ideas why? ...

PHPMailer, AddStringAttachment and Data URI Scheme

I have converted the contents of a canvas element to data (URI Scheme) using toDataURL() ($contact_image_data) and I want to send this via email as an attachment. This is currently how I have PHPMailer set up: $contact_image_data="data:image/png;base64,iVBORw0KGgo[...]"; $filename="test.png"; $encoding = "base64"; $type = "image/png";...

MySQL Error "Too many connections"

Hey everyone, I am using MySQL 5.0 for a site that is hosted by GoDaddy (linux). I was doing some testing on my web app, and suddenly I noticed that the pages were refreshing really slowly. Finally, after a long wait, I got to a page that said something along the lines of "MySQL Error, Too many connections...", and it pointed to my co...

Restricting access to images on a website

I'm putting together a portfolio website which includes a number of images, some of which I don't want to be viewable by the general public. I imagine that I'll email someone a user name and password, with which they can "log-in" to view my work. I've seen various solutions to the "hide-an-image" problem on line including the following,...

php mysql_select_db returns blank page

I'm just starting out writing this code and when I add in the db select and refresh the page, instead of showing all the other html on the page or an error, it just shows up blank. Here's what I've got- $link = mysql_connect('vps2.foo.com:3306', 'remote_vhost30', 'password'); if (!$link) { die('Could not connect: ' . mysql_error())...