php

PHP parsing on includes

I'm including a file init.php which defines path constants. So if I include init.php in a file (index.php) and then in another file (layout/header.php)... is init.php parsed before being added to these files or is it added to the parent file and then the parent file is parsed as a whole? EDIT: Why this is important is because init.php d...

Get fields in a PDF file using PHP

How can I find out the name of the fields in a PDF file using PHP? The only thing I can think of is converting the PDF file to HTML, but that really sounds like overkill. My end goal is to generate an FDF file (this bit I'm happy with) to populate the fields of a PDF file which I don't have control over, so I don't know what field name...

PHP: Defining relative paths compatible with HTML Tags

Consider the following directory structure: ROOT ------ images ............... logo.png ------ includes ............... vars.php ------ layout ............... content.php ------ index.php How do I define a path constant for logo.png in vars.php that is accessible in both index.php and content.php? Should be compatible with HTML Tags ...

CakePHP edit multiple records at once

I have a HABTM relationship between two tables: items and locations, using the table items_locations to join them. items_locations also stores a bit more information. Here's the schema items_locations(id, location_id, item_id, quantity) I'm trying to build a page which shows all the items in one location and lets the user, through a ...

What precautions should I take when using '0' in PHP as a number?

In PHP 0 is treated as boolean false. Hence, whenever I'm in a situation where a function has to return a numerical value and I have it return 0, or when I have a MySQL bool column with possible values of 0/1, and I use code such as this: $active=(isActive()) ? 1 : 0; $this->db->set('isActive',$active); I get a feeling in the back of ...

Using PHP PCRE to fetch div content

Hi, I'm trying to fetch data from a div (based on his id), using PHP's PCRE. The goal is to fetch div's contents based on his id, and using recursivity / depth to get everything inside it. The main problem here is to get other divs inside the "main div", because regex would stop once it gets the next </div> it finds after the initial <d...

Do PHP sessions set any cookies?

I only manually set 1 cookie on my social network site, I do rely heavily on php sessions though and I am wondering if sessions set any cookies behind the scenes? I was just reading up on HttpOnly-cookies and I am just trying to figure out if I can use them any. ...

PHP Compression Options

I need to compress some binary files as quickly as possible with PHP - it needs to be reasonably fast and easy to use. What options can you fantastic people recommend? :) Jamie ...

PHP and regular expressions: how to get the character count of all characters in a string containing HTML, but measuring only 20 visible words?

I am working on a WordPress site where one of the pages lists excerpts about corporate clients. Let's say I have a web page where the visible text looks like this: "SuperAmazing.com, a subsidiary of Amazing, the leading provider of integrated messaging and collaboration services, today announced the availability of an enhanced version...

Implementing the View in MVC or MVP (in PHP)

I've experienced first hand the extent of the horror and foot-shooting that the ugliness of PHP can cause. I'm onto my next project (you may be wondering why I'm not just switching languages but that's not why I'm here) and I've decided to try doing it right, or at least better, this time. I've got some models defined, and I've started ...

Allow user submitted HTML in PHP

I want to allow a lot of user submitted html for user profiles, I currently try to filter out what I don't want but I am now wanting to change and use a whitelist approach. Here is my current non-whitelist approach function FilterHTML($string) { if (get_magic_quotes_gpc()) { $string = stripslashes($string); } $string...

Fails to load remote files from web, but not CLI

I can load a remote file (http) from the php CLI: php > print_r(getimagesize("http://www.google.ca/intl/en_ca/images/logo.gif")); Array ( [0] => 276 [1] => 110 [2] => 1 [3] => width="276" height="110" [bits] => 8 [channels] => 3 [mime] => image/gif ) However, the exact same code from a web script gives ...

Codeigniter + jquery: specify MIME type text/xml in ajax request response

I am making an ajax request from a jquery script to one of my ajax controllers in codeigniter. This process works fine when using data type json. However, when I want to send xml back from the server, the jquery documentation says that the server must specify a MIME type of text/xml. How do I do this with codeigniter. My ajax call loo...

Linux automated code formatting (PHP, JavaScript, HTML, CSS, MySQL)

I am seeking a Linux or PHP program to automate code formatting. Optimally it would handle many languages, but the priority is (highest first): PHP, JavaScript, HTML, CSS and MySQL. Comparability is nice, but not the most important feature. Context / use: automation via Subversion post-commit. I'm working with teams and want to alway...

PHP regex behaves differently on different versions or different OS's

Hello, I'm using two different version of php on two different OS's. One is 5.2.9 running on windows (wamp). One is 5.2.6 running on CentOS 5 (lamp). Regex involving group names works on the Windows one but not on the CentOS. Such example would be /^field_(?<myname>.+)/ Is this an OS issue? Or one with the way PHP was build? Thank...

Can PHP instantiate an object from the name of the class as a string?

Is it possible in PHP to instantiate an object from the name of a class, if the class name is stored in a string? ...

Custom User CSS in PHP?

I would like to add a feature onto my site that would allow a user to choose between multiple styles. I am quite new to PHP but I'm guessing it would be able to be done. I've seen this feature on other sites. How would I go about doing this or could somebody refer me to a tutorial or guide on how this can be done? Thank you. ...

Getting XML keys and values easily in PHP

I'm working with various XML inputs and outputs and simply want to grab the keys and values like you can with an array. Is there a simple function that can convert xml to an array or access the keys and values or am I going about this completely the wrong way? <?php $xmlstr = " <key> <parent1> <child1>val1</child1> <child...

How to load silverlight player into browser to play video using PHP

I am trying to build a web which broadcast video. For that I chose Silverlight as player. But I dont know how to load the silverlight player. I searched in google but nothing helps me. Please give me suggestions. Any help will be appreciated. ...

Passing JSON-encoded variable from PHP to Javascript via POST

I have an multi-dimensional array that I want to send to a PHP script with a Javascript that parses the JSON data and plot it on Google Maps. I'm trying to simulate it using forms: <?php $jsontest = array( 0 => array( 'plate_no' => 'abc111', 'longlat' => array(121.003895,14.631563), 'info' => 'first item' ), 1 => array( 'pla...