php

is it good to declare a function in views ?

i got situation where i have to work on legacy code. One thing, i have to do to have quick result is to define a function in views. Is it good ? how to avoid them ? ...

function name($param, $line = __LINE__, $file = __FILE__) {};

Hi there, Is it possible to have a function automatically contain the line number and the file that the function was CALLED in, as if i call __LINE__ or __FILE__ in the function it will use the line and file the function definition is in. but i dont want to have to pass __LINE__ and __FILE__ into the function every time. so if i set ...

How We Achieve isolation class under test ?

i'm start to learn unit testing. i wonder what is the best way to isolate class under test ? ...

XML parsing of large amount of data

Which is the optimal way of XML parsing(XML may be of large amount of data) in php? ...

PHP function to strip tags, except a list of whitelisted tags and attributes

I have to strip all HTML tags and attributes from a user input except the ones considered "safe" (ie, a white list approach). strip_tags() strips all tags except the ones listed in the $allowable_tags parameter. But I also need to be able to strip all the not whitelisted attributes; for example, I want to allow the <b> tag, but I don't ...

Fastest way of deleting a value in a comma separated list

I've got a list of names separated by commas (they may contain other characters), or be empty, but generally looking like this: NameA,NameB,NameC I need to create a function to delete a name if its present in the list and which restores the comma separated structure. eg: if NameA is to be deleted, I should end up with: NameB,NameC ...

When to use a singleton?

Hello, I have this code: class MyController { public function newUserAction() { $view = new View('myfrontend'); if($this->request->isPost()) { $form = new MyForm; $posts = $this->request->getPosts(); if($form->isValid($posts)) { //... } } $view->display(); } } S...

String to variable-depth multidimensional array

Hi, I'm trying to create a multidimensional array from a string (received from $_GET, input is validated, but not in this example). Each '-' will indicate a level in the multidimensional array. Values can look like this (any form really, as long as '-' is present between keys). The array of values can map to any depth in the multidime...

Best way to track challenges/goals completed by a member?

This is to be an application-agnostic question, but one I'd like to get a better answer on. What is the best set-up to track users completing a challenge or goal? Think similar to Stack Overflow, where if you hit a certain target you're awarded a badge. Currently, I'm the developer of a website and attached Facebook application. I want...

How to show user specific features when they are logged in?

I am trying to write code for a site for my consulting practice. I know how to have a database and how to manage users on the site. But now I want to charge users for custom features they want me to build from ground up. (e.g they want an option to upload pictures or ability to get certain reports via 3rd party API, which for purposes...

Actual input contents are not preseving on most of the browsers [FF,MSIE7/8 and etc]

Hi, I'm working on one application ( using PHP, javascript ). Below is the short description about my problem statement There are two forms avaliable on my application, i.e. SourceFrm and targetFrm. I am taking input on first form i.e. SourceFrm and doing processing on targetFrm. Below is the input which I am taking from SourceFrm : ...

PHP: Get method's arguments?

In php I can check all available methods for an object like so: $methods = get_class_methods($object); But how can I see wich arguments have to be sent to these methods? Is there a function for this? ...

Is the "static" keyword necessary in PHP?

It seems that the uaa() function can be used as a static function even though it is not specifically defined as such. I'm wondering if using the "static" keyword is ever necessary. <?php class foo { functon uaa() { // do something } } ...

Search engine for website

I'm trying to build a search engine for a website. It's mostly a collection of HTML/CSS pages with some PHP. Now that's all there is. All of my content in on the pages. From what I understand to be able to do this I would need to have the content on a Database, am I correct? If so I was considering doing as such, creating a MySQL table...

PHP and Jquery's json

My html file: <script> $(document).ready(function() { $.ajax({ type: "POST", url: "search.php", data: "id=1", datatype: "json", success: function(msg){ $('.result1').html(msg["name"]); } }); }) </script> <s...

secure web application questions

I am implementing a web application which is powered on the backend via a soap server/client interaction. The web site is running over https and authentication is being provided by LDAP. As of now I push all users without a cookie, call it 'userHash' for reference to the login page. The login page accepts a username, pass and checks...

Single instance of a web page

I have couple of php scripts which are called by cron. The cron job runs every 20 mins. Sometimes script finishes the job in few mins and sometimes it takes more than 20 mins. I want to prevent the race condition here. One way I have in my mind is to use the database set the flag when page is running and remove flag when the job is done...

Best way to parse a large, nested XML sheet with PHP?

Hi there, I'm trying to parse a quite large XML-sheet with PHP, but I'm fairly new to it. The XML-sheet contains a couple of thousands of records. Here is an example of the structure used within the sheet: <familyList> <family> <familyID>1234</familyID> <familyDescription>The Jonathans</familyDescription> <childrenList> <child>Suzan</c...

Which odbc connector to use?

I am getting this error from the following code: $result = odbc_connect("DRIVER={MySQL ODBC 3.51 Driver};Server=localhost;Database=$database_name",$database_username, $database_password); Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 i...

Insert string into other string

Hi, is there any function to insert string1 into another string2 if known particular insert place of string2. For example I have HTML code about 2000 chars long. And at 1000 char I want to insert other string which is 200 chars length. Your help would be appreciated. ...