php

How do i set an optional parameter in PHP after the first optional parameter

Hi I'm fairly new to php and I am trying to figure how do I set an optional parameter after the first optional parameter? For example I have the following code: function testParam($fruit, $veg='pota',$test='default test'){ echo '<br>$fruit = '.$fruit; echo '<br>$veg = '.$veg; echo '<br>Test = '.$test; } If i make the following calls...

Replace URLs in text with HTML links

Here is a design though: For example is I put a link such as http://example.com in textarea. How do I get PHP to detect it’s a http:// link and then print it as print "<a href='htttp://example.com'>http://example.com&lt;/a&gt;"; I remember doing something like this before however, it was not fool proof it kept breaking for compl...

Weird behavior with mysql_affected_rows() in PHP

I have a table named user_ips to keep track of users in case they delete their cookies or change browser. So anyway, the following code is simple. It updates entries in user_ips that are equal to the user's id and IP. If the query did not update any rows, then it means that IP for that user is not in the table, so it inserts it. $site->...

.NET or PHP, Corporate or Open-Source ?

I am very experienced in working with open-source technologies like PHP, MySQL, Apache and others. I feel like home working with them and the code comes to me with little effort. I recently started playing with the ASP.NET technology (I know it doesn't compare to PHP, or does it?) and everything seems very easy, but still I don't feel l...

How do you match one of two words in a regular expression?

I want to match either @ or 'at' in a regex. Can someone help? I tried using the ? operator, giving me /@?(at)?/ but that didn't work ...

Which MVC layer should set this value?

I'm working on a report that displays information about our company's sales locations. One of the bits of information is the 'last visit date' of the location. If the location has never been visited, I have to display (in the current language) 'Never' in red. There are several values like this one, this is just the example I'm using. Cu...

php function to split an array at each blank line?

Hello, I'm building a script which will open a saved text file, export the contents to an array and then dump the contents in a database. So far I've been able to get the file upload working quite happily and can also open said file. The trouble I'm having is the contents of the file are variable, they have a fixed structure but the co...

Using PHP to call a WCF web service with multiple bindings

I have a WCF web service which allows both Basic HTTP and WS-HTTP clients, both over HTTPS using user name & password authentication. This is achieved with two bindings on the same service. So, the service is at https://foo.com/Service.svc, the Basic HTTP (SOAP 1.1) endpoint is https://foo.com/Service.svc/Unp11, and the WS-HTTP (SOAP 1....

Looping Through GET, POST, and COOKIE to Sanitize?

Considering that everyone is always worried about User Data (And Rightly So), would it be sufficient to simply loop through each external array when you get it, and apply a mysql_real_escape_string(). I'm curious to if this is a bad idea. Something like: function getExternalData($type='GET') { $type = strtoupper($type); $dat...

Get the date of next monday, tuesday, etc

I would like to find the date stamp of monday, tuesday, wednesday, etc. If that day hasn't come this week yet, I would like the date to be this week, else, next week. Thanks! ...

PHP Inheritance and MySQL

So I'm trying to adopt good object oriented programming techniques with PHP. Most (read all) of my projects involve a MySQL database. My immediate problem deals with the users model I need to develop. My current project has Agents and Leads. Both Agents and Leads are Users with much of the same information. So, obviously, I want a clas...

Why the trailing slash in the web service is so important?

I was testing a web service in PHP and Python. The address of the web service was, let's say, http://my.domain.com/my/webservice. When I tested the web service in PHP using that URL everything worked fine. But, when I used the same location but in Python using SOAPpy I got an error. Below is the code I used to communicate with the web s...

Join tables problem - MySQL & PHP

Hello, I'm trying to join two tables. The first table has a list of 11 items which are 'site_names' with an auto id field of 'id'. The second table that I want to connect has an auto id field of 'desc_id' and another field of 'descriptions'. This second table currently has 3 rows of data that I want displayed only for id 1 in table 1. ...

OO PHP direct member acccess

I always thought you should never set/get a member variable directly. E.g. $x = new TestClass(); $x->varA = "test": echo $->varB; I thought you should always use object methods to access member variables. But I've just been looking at __set and __get, which imply it's ok to access members directly. Any thoughts? ...

removing strange characters from php string

this is what i have right now Drawing an RSS feed into the php, the raw xml from the rss feed reads: Paul&#8217;s Confidence The php that i have so far is this. $newtitle = $item->title; $newtitle = utf8_decode($newtitle); The above returns; Paul?s Confidence If i remove the utf_decode, i get this Paul’s Confidence When i ...

Manipulate an Archive in memory with PHP (without creating a temporary file on disk)

Hi, I am trying to generate an archive on-the-fly in PHP and send it to the user immediately (without saving it). I figured that there would be no need to create a file on disk as the data I'm sending isn't persistent anyway, however, upon searching the web, I couldn't find out how. I also don't care about the file format. So, the ques...

Dealing with long server-side operations using ajax?

Hi there, I've a particularly long operation that is going to get run when a user presses a button on an interface and I'm wondering what would be the best way to indicate this back to the client. The operation is populating a fact table for a number of years worth of data which will take roughly 20 minutes so I'm not intending the int...

Need better structure of my code

this is my front controller $pages = array("matches", "boards", "search", "articles", "interviews", "userlist", "teams", "servers", "awards", "gallery", "qids"); if (!$_SERVER['QUERY_STRING']) include('home_en.php'); elseif (isset($_GET['matchid'])) include('matchid.php'); elseif (isset($_GET['boardid'])) include('boardid.php'); elseif...

How do blog systems do this?

I have a social network so a blog is only you could say a widget of the site for a user, so every user can have a blog, I would like to make this blog as nice as possible. WHen you go to a users blog page it shows all blogs for the current month. My question, how can I show a column on the side like this July 2009 June 2009 May 2009 Ap...

Regex Match PHP Comment

Ive been trying to match PHP comments using regex. //([^<]+)\r\n Thats what ive got but it doesn't really work. Ive also tried //([^<]+)\r //([^<]+)\n //([^<]+) ...to no avail ...