php

Regular expression help

Hello all, I have a lot to learn as far as regular expressions are concerned. I have an associative array like so: array( "label"=>"Special", "title"=>"Category", "onclick"=>"dosomething()", "options"=>array( "one"=>"something" ) ) I am trying to use preg_match_all on the array like so: $match="on*"; fo...

How to treat payment status on IPN

I was thinking how to treat the payment status in my database. I want to store all payments in my database (also the pending ones). But we have to check in the IPN process if there is already a payment with such txn_id, right? Let's suppose I receive a payment that is pending and I store it on my database. After that, when the payment ...

passing array parameters to smarty PHP template include

On a PHP site using the smarty template engine (or at least a close relative of smarty), I am calling a template include file ("header.html") which contains this code excerpt, along with other HTML omitted here for clarity: <title>{$title|escape:"html"}</title> {if isset($META) && $META} {foreach from=$META item=m} <meta nam...

PHP Regex to get youtube video ID?

Forgive me for the beginner regex question but I was hoping that someone could show me how to get the youtube id out of a url regardless of what other GET variables are in the URL. Use this video for example: http://www.youtube.com/watch?v=C4kxS1ksqtw&amp;feature=related so between v= and before the next & ...

How to get the number of sub-page/child pages that exist in Wordpress?

Basically I am trying to show something like "Viewing PageNumber of TotalNumberOfPages" in each subpage for a specific parent page. So i am trying to figure out how to count the number of sub-pages/child pages that exist and display them on a subpage? ...

PHP/MySQL: Rating system - Sum each user vote or update general votes table?

Hi. Each user can vote once per item (only registered users can vote). So I have a user-votes table that include the user ID, voted Item ID and the vote value (from 1 to 10). I need to show the total votes and rating for each item so I want to know what is best: Get from the user_votes table all the votes for that item OR save the vote ...

PHP URL Encoding/Decoding Pretty Quotes across form field's %u2019

For some reason, after submitting a string like this Jack’s Spindle from a text form to php, I get: Jack%u2019s Spindle This is not what PHP's urlencode() would do, which would be Jack%92s+Spindle or rawurlencode() = Jack%92s%20Spindle Thus, urldecode() and the raw version don't work to decode that string... Is there another function ...

Need help with $.ajax function - How to send an associative array ?

I would like to send data using $.ajax like this: $.ajax({'url': 'my.php', 'type': 'POST', 'data': arr, 'success': function(response) { alert(response); } }); The problem is that arr is an associative array that looks like: arr['description_0'] = 'very nice picture!'; a...

How to make PoEdit correctly parse custom "ngettext" implementation?

I've coded a gettext wrapper that makes the whole process of l10n a little bit simpler but somehow I can't get PoEdit to correctly identify and parse plural version calls to the function. This is what I originally had: _e(array('%d house', '%d houses'), 5); But that doesn't work at all, PoEdit picks nothing at all. I also tried: _e('...

jquery ajax based registration form

Hi I must now seek help after too many hours of failure. I'm using a basic registration form with Ajax, but the form is not connecting to the database. I'm obviously overlooking something. So here's the field i want to validate. obviously, its the username. Username:<input type="text" name="user" id="user" maxlength="30"> <span id="...

merge two arrays, while maintaining the numeric keys.

im trying to merge two arrays together. both have numeric keys and are unique. when i use array_merge, it re-indexes starting at 0. so lets say i have [2] = abc [5] = cde and i have [32] = fge [13] = def i want to merge these two together maintaining the unique keys. below is the explaination on the current merge behavior.. an...

Link to download an image or other file, next to a link that opens a new tab with the image

I'm building an image gallery. Under the images, I want to display links under each image where one says "View full image" and another one says "Download image". Is it possible? EDIT: I realized that I've provided insufficient information. The images in my gallery have three sizes. The smallest are displayed with views. The medium is di...

Create an UL from comma separated Values in PHP

I'm creating a user input where I want them to list links as well as descriptions. Doing this from scratch, so I'm open to sytax suggestions. I was thinking of something like this: www.ebay.com | "my Ebay" , http://www.craigslist.org?s=bla | "Craiglist" , www.twitter.com/ev | "My Twitter" I'd like to convert this into an UL with php....

What principles should I follow to code in PHP with fewer Java-like objects and more similar to Clojure's functional programing principles?

I was introduced to Clojure not long ago, and while I haven't fully assimilated all of it's concepts, It has given me an alternative to Java and PHP's OO that I really want to move towards. I consider Clojure's systems to be my ideal. I know that I want to let it inform my PHP coding style as much as I can. I really don't like OO in P...

Getting user's current time (not server or computer clock BUT ACTUAL real time) and pass as a variable into php

How can i do this? EDIT: I'm not sure if this would work but sometimes you get those annoying pop-ups that tell you what city/suburb you're in (usually for dating sites) - could we somehow extrapolate from that data what the time is??? Is this data based on a reverse IP lookup?? Any suggestion code to get me started (I don't really kn...

Replace same character several times with different string

Hello, I have a string with the same character in it several times and I want to replace each occurrence of this character with a different string from an array. I.e. just like in prepared statements: String: "SELECT * FROM x WHERE a = ? AND b = ?" Array: ['alpha', 'beta'] Result: "SELECT * FROM x WHERE a = alpha AND b = beta" Is the...

Accessing Many-to-Many Field in Doctrine

This must be simple, but I can't seem to find the answer online nor figure it out through trial and error. I have a class Deck and a class Card which have a many to many relationship with each other. I'm fairly confident that I am adding Cards to Decks correctly (they are being written correctly into the DB, junction table and all), but...

Is the state design pattern overkill for a PHP form?

I have a page that, when accessed displays a table of information related to a video: Embed code Title Description Current gallery Thumbnail image This information is read-only when the page is first accessed. There is a select menu that has the following options: Edit Description Create Thumbnail (Upload/Replace) Edit embed code ...

PHP make if shorter

What is a true way to write like: if ($variable == '(value1/value2/value3)' ) { } It should work similar to: if ($variable == 'value1' || $variable == 'value2' || $variable == 'value3') { } Just want to make this code shorter (now I use switch). Thanks. ...

Creating a cookie using PHP but having difficulty reading from javascript

I have set my cookie in PHP using the following: setcookie("id", 100, time()+100000, "/AP", "www.mydomain.com", 0, true); When I look at the cookies stored in the browser it looks like this: Name: id Content: 100 Domain: .www.mydomain.com Path: /AP Notice the . in the Domain When I set a cookie in javascript I get the same ...