php

How do I create a Unary association in CakePhp?

Is there a shortcut for creating Unary associations in Cake? For example, a user is a friend of another user. I'm pretty sure it's going to violate cake's conventions if I try it the hard way and code the associations myself. Cake has HABTM: var $hasAndBelongsToMany = array( 'User' => array( 'className' => 'User', 'joinTable...

Adding item to array PHP

I'm building a shopping cart for a school assignment. I'm pretty much there except for adding the items to the cart variable. I've set up my cart session with: $_SESSION['temp_session'] = array(); and then, when a item is added to the cart, this code is executed if (isset($_POST['addtocart'])) { $item_name = $_POST['item_name']...

Reading the .htaccess DirectoryIndex and Rewrites with PHP

Is there an inbuilt way to read the active DirectoryIndex in .htaccess (or httpd.conf etc) with php? Also, is there a way to determine which file the httpd will execute using PHP given a url if rewrites are being used? Basically, given a URL, I want to use PHP to figure out which file the httpd would initially invoke. Thank you. ...

Utf "\x94" validation error in html/xhtml form for php

Okay XHTML want's to play some games with me, I was doing fine, until up to now. Looking at the two code snippets below I don't see anything wrong with them, however when I try to validate I get "The error was: utf8 "\x94" does not map to Unicode on line 91, I have commented line 91 to denote the problem area. And what's up with "Sorr...

Send multi message using jquery plugin in multi-row data?

i use jquery.form to send a form, but in may case below how use this jquery plugin $('#htmlForm').ajaxForm({ target: '#htmlExampleTarget', success: function() { $('#htmlExampleTarget').fadeIn('slow'); $('#htmlForm').hide(); } }); for($i=1;$i<= 10;$i++){ //form $1 form name="form$i" action="blabla.php" input type="text" n...

What encoding is this... and how do you escape it in php?

Im working on an imdb data scraper for a site, and I they seem to encode everything in a weird encoding I never saw before. <a href="/keyword/exploding-ship/">Exploding&#xA0;Ship</a> A Bug&#x27;s Life Is there a php function that will convert these to regular characters? ...

Mixing php and html

If I can ask that answers refrain from pointing towards frameworks or other libraries, I would appreciate it. I am aware of those, and am after more of an answer based on experience for quick little hacks. Start with some base html <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> ...

Access a website by a bot but only after setting a variable by a browser/human

We are working on a website of a brewery using Drupal. As minors under 18 are not allowed to view the website, any page accessed is passed through a module (legalage) and if the user clicks "continue" so as to confirm his/her age being more than 18 the site is shown to the user saving the legal age as true. The problem is when search e...

Preserve Autoincrement ID Within MySQL Transaction

I have two MySQL database tables that are meant to hold data for eshop orders. They're built as such (extremely simplified version): CREATE TABLE `orders` ( `id` int(11) NOT NULL auto_increment PRIMARY KEY (`id`) ); CREATE TABLE `order_items` ( `id` int(11) NOT NULL auto_increment, `orderID` int(11) NOT NULL, PRIMARY KEY (`id`)...

Is it possible to group $_POST variables?

I have a huge form (for an internal CMS) that is comprised by several sections, some of them are optional some of them are compulsory. All is under an humungous form (it has to be like this, no ajax, no other ways :-( ) Since in a Dilbertesque way everything get changed every second I was wondering if there is any simple way of groupin...

How do I get the count of all the products in a category and its sub categories (and sub-sub categories)?

The category table looks like somewhat as below: id -- name -- parent_id 1 -- Men -- 0 2 -- Women -- 0 3 -- Shirts -- 1 4 -- Half-sleeve -- 3 5 -- Full-sleeve -- 3 Relationship table: Product_id -- Category Id 1 -- 2 2 -- 2 3 -- 4 .... I can retrieve the number of products in any one category and...

How can I compare an object with the parent class in php?

I want to compare the class of an object with the current class, and in inherited methods to refer to the parent class. This is the only way I can think of doing it: class foo { function compare($obj) { return get_class($obj) == get_class(new self); } } class bar extends foo { } $foo = new foo; $foo->compare(new foo); //true $foo->comp...

Yii framework - what is the file ".yii" in some folders

There is ".yii" file in the following folders: /assets/ /images/ /protected/commands/shell/ /protected/extensions/ /protected/messages/ /protected/runtime/ /protected/views/system/ /themes/classic/views/layouts/ /themes/classic/views/site/ /themes/classic/views/system/ What is it? ...

Smarty PHP/template output problem

I have problem outputing this to page.. for ( $i = 0; $mainarray[$i] != ''; $i++ ){ $query = mysql_query("SELECT ... FROM ... WHERE id=$i") or die(mysql_error()); while($tmp = mysql_fetch_assoc($query)) { $something[] = $tmp; } $smarty->assign('stuff'.$i, $something); } I could manualy do it like {section name=i loop=$stuff1...

How to map file path from different folder location easily?

how to map the path to the file easily? public_html/api/function.php <?php function writetologfile($content) { $filename = 'logfile/testing_randomstring.txt'; if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } fclose($handle); } ?> the actual path of the text file i...

Lexical Analysis libraries

I would like to make a piece of software able to regognize whether a sentence is positive or negative. Is there any Lexical Analysis libraries arround? I don't really know where I should start. ...

CodeIgniter get_where

Hi there, I’m attempting to use get_where to grab a list of all database records where the owner is equal to the logged in user. This is my function in my controller; function files() { $owner = $this->auth->get_user(); $this->db->get_where('files', array('owner =' => '$owner'))->result(); } And in my view I have the follow...

Check for files (robots.txt, favicon.ico) to a website php

I would like to check to a remote website if it contains some files. Eg. robots.txt, or favicon.ico. Of course the files should be accessible (read mode). So if the website is: http://www.example.com/ I would like to check if http://www.example.com/robots.txt. I tried fetching the URL like http://www.example.com/robots.txt. And sometim...

PHP function with unlimited number of parameters

How do I write a function that can accept unlimited number of parameters? What am trying to do is create a function within a class that wraps the following: $stmt->bind_param('sssd', $code, $language, $official, $percent); ...

What does the following mean in PHP?

what does the colon mean in php in the following example. ::1 if($host == "" || $ip == "::1") ...