php

(Hopefully Simple) Question about Unit test seperation

Hi, This question is related to PHPUnit, although it should be a global xUnit design question. I'm writing a Unit test case for a class Image. One of the methods of this class is setBackgroundColor(). There are 4 different behaviors I need to test for this method, Trying to set an invalid background color. Multiple invalid paramete...

PHP inherited array properties

I have a class hierarchy in PHP 5.2.9. The base class has a protected property which is an associative array. The child classes can add some elements to the array. The child classes are declared in the separate files (plugins), which will be created and added by multiple developers. Which is the best way to add the elements to the pr...

unreadable var_dump() output on Snow Leopard?

I have xdebug configured as shown below but the error-output is totally unreadable. Do you have an idea what's wrong with the setup? TIA & best regards Setup: Apache/2.2.13 (Unix) PHP/5.3.0 on Snow Leopard Server Config from php.ini: xdebug.remote_autostart=0 xdebug.remote_enable=1 xdebug.remote_host=10.0.1.9 xdebug.remote_connect_ba...

PHP deepening XML structure

given the following XML structure (i have this in an XML-file, with lots of other content - the <p> tags are just there to indicate that other tags may follow): <TITEL1>...</TITEL1> <p>..</p> <TITEL2>...</TITEL2> <TITEL3>...</TITEL3> <TITEL3>...</TITEL3> <P>...<P> is there a way to get to this using PHP (write it to a new file...

in PHP, how to remove specific class from html tag?

given the following string in PHP: $html = "<div> <p><span class='test1 test2 test3'>text 1</span></p> <p><span class='test1 test2'>text 2</span></p> <p><span class='test1'>text 3</span></p> <p><span class='test1 test3 test2'>text 4</span></p> </div>"; I just want to either empty or remove any class that has "test2" in it, so the resu...

How do I indicate long text into a smaller fixed column with CSS?

Hi there, how do I fit long text into fixed with column where I have place for only line of text? I would need to shorten the text to fixed width (lets say to 100px) and I would like to add dots "..." at where string gets cut. Something like this for example: My string is "Some really long string that I need to fit in there" and output...

Transform Ruby-on-Rails code to PHP

This may sound odd but a right answer might save me hours of coding. I have found a ruby-on-rails class (~10 files, ~1000 lines total) that serves a specific purpose (payment gateway integration). However, I am not familiar with ruby at all and need to use that class in a PHP application. I am wondering if there is a program that can per...

Dynamic static method call in PHP?

Hi, Please could someone experienced in PHP help out with the following. Somewhere in my code, I have a call to a public static method inside a non-instantiated class: $result = myClassName::myFunctionName(); However, I would like to have many such classes and determine the correct class name on the fly according to the user's langua...

PHP - Fatal error: Unsupported operand types

I keep getting the following error and I was wondering on how to fix? This is the second time I got this error I fixed it the first time but for some reason I cant fix it the second time. Fatal error: Unsupported operand types on line 103 Here is line 103. $avg = (round($total_rating_points / $total_ratings,1)); Here is the full c...

how to get the number of weeks of current year using Zend_Date class

how can we get number of weeks of current year, for example if it's 2009 there are 53 weeks and 2010 has 52 ...

any html/css parsing library for ruby & PHP?

I am about to finish my script that parses/scrapes website using mechanize&ruby. I need to port my script to PHP in the future. My question is if there is any library available for both ruby and php or if anybody can recommend any other approach to this? ...

most secure way to password protect admin files/folders?

what is the most secure way to password protect admin files/folders? im on apache/php ...

Zend Framework Models not loading by autoloader

I've setup my application with Zend_Application. I have an _initAutoload() method in my Bootstrap.php wich looks like this: public function _initAutoload(){ $this->bootstrap("frontController"); $front = $this->frontController; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('Cli...

adding php variable into Xpath

Hi , i just need to add in a variable into the xpath my code is as followed $target = $xml->xpath('//gig[@id=$1]'); but I need it too but something like $target = $xml->xpath("//gig[@id=$" $change . "]"); Is this possible ? If so could some one help ? ...

Is there a way to automatically take a screenshot of a website through a URL?

I am trying to find a PHP script (or a script in a different language) that after passing a URL, it takes a screenshot of the website for that URL. So for example if I pass stackoverflow.com, it should take a screen shot of the website (in this case the homepage), keep it on the server, and provide a link to that pic. Is there an easy w...

How to strip all spaces out of a string in php?

How can i strip / remove all spaces of a string in PHP? Say i have a string like $string = "this is my string"; the output should be like "thisismystring" How can i do that? ...

Filtering email addresses in an array -php

Hello, I have a php array containing email addresses as array(email_address1 => name1, email2 => name2) format. I need to check that emails are valid and I can foreach and foreach($arr as $email => $name) { $new = array(); if(filter_var($email, FILTER_VALIDATE_EMAIL)) { $new[$email] = $name; } return $new; } Can I achie...

PHP Loop do some once the loop as finished

I have this PHP loop, foreach($returnedContent as $k => $v) { $imageName = str_replace($replaceData, "", $v['contentImageName']); echo "<a class='contentLink' href='".base_url()."welcome/getFullContent/$v[contentId]'>"; echo "<img src='/media/uploads/".strtolower($v['categoryTitle'])."/".$imageName."_thumb.png' alt='$v[cont...

Generating a JavaScript array from a PHP array

Suppose that I have a string $var: //php code $var = "hello,world,test"; $exp = explode(",",$var); Now I get the array as exp[0],exp[1],exp[1] as 'hello', 'world' and 'test', respectively. I want to use this all value in javascript in this: var name = ['hello','world','test']; How can I generate that JavaScript in PHP? ...

What's the best practice to set html attribute via PHP?

When doing this job in PHP,one may meet this kind of issue: <span title="<?php echo $variable;?>">... The problem is that if $variable contains double quotes,should change it to \" And that's not the whole story yet: <span title='<?php echo $variable;?>'>... In this case,we need to change single quotes to \',but leave double quote...