php

Posting to a Facebook (fan) page wall

I have a blog (wordpress) and a facebook fan-page for my blog (with more than 1 fan!). I would like to post a message to my FB wall, every time I post something on my blog. Preferrably PHP. The same question is already asked here, but this question isn’t going anywhere. The question dates from march, but Facebook has updated their API s...

PHP maybe regex

OK, so I have a new project with me, it is basically on solving logical and reasoning type of problems. Like in maths you are given a figure and asked how many triangles are in it. What I have to do is. User enters a code and a word. example word -> example code -> aesxxasskmpaalee here if we remove certain characters, we can form exa...

PHP and Postgres: catching errors?

How should I prepare the code if it something fails? With try-catch statement or? function delete_question ( $question_id ) { $dbconn = pg_connect("host=localhost port=5432 dbname=heoa user=heoa password=123"); // removes questions and its dependencies: answers and tags $result = pg_query_params ( $dbconn, 'DELETE F...

How do I throttle my site's API users?

The legitimate users of my site occasionally hammer the server with API requests that cause undesirable results. I want to institute a limit of no more than say one API call every 5 seconds or n calls per minute (haven't figured out the exact limit yet). I could obviously log every API call in a DB and do the calculation on every request...

How can I check that an array key exist if the array does not exist in PHP

I am in a bind, multiple times on a page for different form items, I insert a css div class into a form item ONLY if an error_array key exists, this is how I highlight a form item that has an error in it. Works, great if I have an error because then my error array is set, problem is before an error is set, it tries to look for an array ...

does php have any concept of config files or a global.asax?

Coming from a .net background so bear with me! Does php have anything like a web.config or a global.asax file or is it simply dropping the application in the file system and boom it is running on the web server? (obviously dropping the files mapped in apache for the domain etc). Specifically thinking of setting up wordpress. ...

Get root DNS entry from php server; get domain name without www, ect...

How would one get the root DNS entry from $_SERVER['HTTP_HOST']? Input: example.co.uk www.example.com blog.example.com forum.example.co.uk Output: example.co.uk example.com example.com example.co.uk EDIT: Lookup list is very long ...

Intercepting calls to methods in PHP

I have a class with static methods, and I would like to intercept method calls before the methods are called. So if I call $model = DataMapper::getById(12345); then I want some method in DataMapper to be called before this method is called, and then optionally this intercepting method can subsequently call self::getById(12345). Is t...

Converting ANSI escape sequences to HTML using PHP

This is a similar question to this one. I would like to convert ANSI escape sequences, especially for color, into HTML. However, I would like to accomplish this using PHP. Are there any libraries or example code out there that do this? If not, anything that can get me part way to a custom solution? ...

Replacing Classic Login with OAuth for a single user twitter bot

My site uses a php function to tweet an update whenever an event occurs. Right now I'm using the classic login technique, so the username and password for the associated Twitter account are just hard-coded in. The function looks like this: function sendTweet($msg) { $username = 'username'; $password = 'password'; $url = 'http://twitt...

php mail function not getting the emails

ok, so I put together a very basic mail function and while testing this, I used a couple of email accounts, one my google account and the other my work account. I get all emails at the google account, but not to those pointing at my work. I'm thinking that could be because they have been caught up with the anti-spam software. Any ideas o...

How can I use a variable variable in PHP?

Here is what I am trying to do: <?php $my_str = "My String"; $str = "%my_str"; $str = str_replace("%", "$", $str); echo $str; ?> The above code prints '$my_str' to the screen. But I want it to print 'My String', as in the actual value of the variable $my_str Anyone know how to do this? The reason I want this is bec...

Postgres: insertion and deletion

I sense an easier way to do the code. How can I do the deletion/insertion shorter? // to delete the old tags before inserting new tags $result = pg_query_params ( $dbconn, ...

Best way to store a short number in mysql

I am trying to fix a project that someone else coded, it is a mess! On an edit user profile page they have something like this below which will list all available radio select boxes for the options a user can select for there education level, this is just 1 item, there is many items like it so based on the answers here, I can apply it...

Regexp for extracting a mailto: address

I'd like a reg exp which can take a block of string, and find the strings matching the format: <a href="mailto:[email protected]">....</a> And for all strings which match this format, it will extract out the email address found after the mailto:. Any thoughts? This is needed for an internal app and not for any spammer purposes! ...

What does the -f flag mean in the fifth parameter in the PHP mail function?

Thanks in advance Jon ...

How can obtain the parameters in a link inside a php file?

Hi: I client of mine, have 542 php files (yes a lot) each one of them call a iframe with certain parameters every one different. So i wanna make this a little more efficent, and convert all files to a database, but for this i need to obtain 2 things The contain of the title tag One parameter of the iframe (cat) I show the iframe exa...

shopping cart for non registered users

I am in the process of making a website that involves a shopping cart. There are two major requirements: The user experience guys want login/authentication to be the very last step in the entire work flow. The user gets to do all the shopping and is asked to login only at the time of checking out. The shopping cart shouldn't expire(n...

PHP Mysql Auto Quote?

When inserting a row in mysql database, string values need to be enclosed in quotes where integer don't need to. Is there any class or library that takes care of this automatically so that I can just pass to a 3rd-party function an array of fieldnames and values and don't have to worry about putting string values in quotes? Thanks, ...

count() causing "unexpected T_STRING" error?

I'm trying to define a new shortcode in WordPress, and I get the following error when the function is loaded (just loaded, I haven't tried to call it anywhere yet): Parse error: syntax error, unexpected T_STRING in /pathtomytheme/user_functions.php on line 105 Here's the code; line 105 is "$cat_n = count($cats) – 1;": function user...