php

PHP - preg_match?

I'm not very good with expressions... I've looked at some online tutorials, but I'm still not getting it. Basically, I'm trying to return TRUE if a string is formatted like this: 4 digits + space + 2 digits and convert it to a date. So, the string will look like: 2010 02, and I'm trying to output February, 2010. I'm trying to use p...

Little explanation of this mysql code

I got this answer from somebody on another Q before, but I would like to get an explanation of this, so that I fully understand the problem. I have a table, with a column which contains a value of either "private" or "company". Thing is, I want to check how many "private" and "company" values are in my records, so that I can display the...

Send \n with jquery ajax

I made a little script that send a textarea content to PHP page with get ajax request: $.get('./data/pages/admin/actions.php?savepost=1','&post_id=' + $(box).attr('id') + '&text=' + new_text,'text'); new_text get content from textarea with val(); When I save the text from php it has no \n character. Some1 can solve my problem? Thanks...

How to set multiple PHP classes intoa Debug mode?

What would be the best way to set 10+ PHP classes into Debug mode easily but still keeping the classes non-dependent of other stuff? If I set a Global Constant then check for it's value inside every class then every class is reliant on this constant being set. Meaning if I try to use the class in another project it is relying on a Cons...

Count rows from results of a "mysql_query"

If I have this: $results = mysql_query("SELECT * FROM table_name WHERE id=$id"); is there then any way to check how many rows which have a field-value of "Private" or "Company" ? I need to show the user how many "Private" and "Company" records where found, without making another query. (There is a column called 'ad_type' which contai...

php - extract array into global variables

The manual on "extract" shows you can extract an array like: extract(array('one'=>1,'two'=>2)); into $one,$two... But the extract function doesn't return the variables. Is there a way to 'globalize' these variables? Maybe not using extract, but a foreach loop? EDIT: (explanation about what I'm trying to achieve) I have an array co...

Display image based on date in PHP

Somewhere on my computer I had a PHP script for displaying an image based on the date, that would allow me to display different images on specific dates, or between selected dates, and display a default date if the current date wasn't one listed with a specific image to display. I recently had a problem with one of my hard drives though...

FPDF Header Question - Driving me crazy!

I am trying to generate a PDF that outputs Item Names onto a template PDF (using FPDI) with the Username listed on the top of each page. Every user can have a different number of items (i.e. if there are 1-4 items, only output one page; if there 5-8 items, output two pages, etc.) Here is an example of what I am trying to do: http://www...

PHP syntax to call methods on temporary objects

Is there a way to call a method on a temporary declared object without being forced to assign 1st the object to a variable? See below: class Test { private $i = 7; public function get() {return $this->i;} } $temp = new Test(); echo $temp->get(); //ok echo new Test()->get(); //invalid syntax echo {new Test()}->get(); //...

How do I JOIN these tables?

I have two tables: **WEEK** -id -week # **ITEM** -id -name -is_marked -week # My final desired result is to have a table that has a rowspan="3" table cell with week # in it, followed by the three results for each week from SELECT * FROM item WHERE week = week_number AND is_marked = 1 I don't know if I need to JOIN anything bec...

How to add CSS classes to Zend_Form_Element_Select option

Hi, I'm trying to add a CSS class to a Zend_Form_Element_Select option, but I just can't find a way to do it. The desired output would be something like this: <select name="hey" id="hey"> <option value="value1" style="parent">label1</option> <option value="value2" style="sibling">sublabel1</option> <option value="value3" s...

PHP - Downloading very large files with fsockopen(), fgets() and feof()

I have a simple download function in a class that might be dealing with files of many hundreds of MB at a time from an Amazon Web Services bucket. The whole file cannot be loaded into memory at once, so it must be streamed directly to a file pointer. This is my understanding as this is the first time I've dealt with this issue and I'm pi...

Regular expression, replace multiple slashes with only one

It seems like an easy problem to solve, but It's not as easy as it seems. I have this string in PHP: ////%postname%/ This is a URL and I never want more than one slash in a row. I never want to remove the slashes completely. This is how it should look like: /%postname%/ Because the structure could look different I need a clever pr...

How to replace ereg?

Hi all, I'm getting the following message for some php I have to use but did not write: Deprecated: Function ereg() is deprecated in /opt/lampp/htdocs/webEchange/SiteWeb_V5/inc/html2fpdf.php on line 466 This is line 466: if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3)) I tried simply replacing with preg_match, but it couldn't re...

How to set default value to a extra field in a symfony form

What i need to do is customize my default userForm by adding a 'passwordagain' field and set the value to the new field equal to the 'password' field. My code: class UserForm extends BaseUserForm { public function configure() { $this->widgetSchema['password'] = new sfWidgetFormInputPassword(); $this->widgetSchema['passwordagain'] = n...

How can I replace the deprecated set_magic_quotes_runtime in php?

Hi all, I'm getting this message when I try to run a php script I have to use but did not write. Deprecated: Function set_magic_quotes_runtime() is deprecated in /opt/lampp/htdocs/webEchange/SiteWeb_V5/inc/fpdf.php on line 1810 Here is line 1810: set_magic_quotes_runtime(0); If this is a deprecated function, what can I replace it ...

how to load xml file once for all the function in php

i have written a php code that will make use of one xml feed. This feed is used by about 12 functions for various calculations.So in each function i use simplexml_load_file to load the file. Several functions are called in the same page to display variuos results depending on the variables passed. I would like to know is there a way that...

Create a symlink without shell access and in safe mode?

On a shared hosting package running the LAMP stack and PHP, with no shell access and PHP in safe mode (= exec() being disabled), with only FTP access, do I have a chance of creating a symbolic link somehow? I just checked, I can't even use the sneaky workaround of inserting a cron job that executes the ln command. ...

Using Git with your CakePHP Project

I use git as my primary version control system, and have recently started using git on my CakePHP projects. This is my current .gitignore file: app/tmp vendors/ As used in the cakephp git repo, but this causes a bit more work for me when deploying the project to a server, because I have to go in and create all the app/tmp/ sub-direct...

403 Forbidden on symlink in web root

I am on a shared hosting package on a LAMP stack with no shell access. I can create symlinks using PHP's symlink() function. Let's say my web root is /home/www/user1/public Let's say I have a real directory named /home/www/user1/public/real_dir And I create a symlink named /home/www/user1/public/fake_dir pointing to real_dir Why wo...