php

CakePHP and HABTM Model Limit Error

I've got a series of Post models that hasAndBelongsToMany Media models. In certain function calls inside of the Post model, I don't need to retrieve the entire list of Media models. However, when I use the following code: $this->unbindModel( array('hasAndBelongsToMany' => array('Media')) ); // Rebind to get only the fields we need: $t...

How do I insert HTML into a PHP DOM object?

Hello, I am using PHP's DOM object to create HTML pages for my website. This works great for my head, however since I will be entering a lot of HTML into the body (not via DOM). I would think I would need to use DOM->createElement($bodyHTML) to add my HTML from my site to the DOM object, However DON->createElement seems to parse all HTM...

PHP Grab Image from html code - simple

I have a text editor on my web page, on that text editor i put image and than i use that image in different parts of my website, but in different places the image size differs. The image in database is stored this way: <div><img width="210" height="150" alt="" src="/portali/userfiles/image/Kategorite/Teknologji/-1.jpg" /></div> Now in...

PHP Login via sessions doesn't work on first attempt (in new window)

So I'm working on an application that requires a user to login before accessing any 'sensitive material'. The login script works like this: User enters U/P->Script validates data->If valid, SESSION variables are set. This is a very strange problem, since SESSIONS are handled by the server. The problem: When first opening the script i...

How to delete part of a string

If I have a string of characters like so: This is a test string and I wa And I wanted to delete everything after the "I" which would also include the space after the I, how would I do this? I definitely need to start at the end of the string and count backwards to the last space but I'm not sure how to do this. ...

Doctrine 2 Validations

Hello fellow PHPers! It does not seem like Doctrine 2 has built-in validation. Is this a feature that will be supported in the future? How and where do you validate your Doctrine 2 entities? Guess I have to write my own validation engine for Doctrine. thanks ...

Get Wordpress to Coincide with Zend Framework at the base level

Hi all, I have a current wordpress blog with the blog posts URLs structured as http://somedomain.com/2010/02/postname I'm now installing a zend framework implementation at the base level http://somedomain.com/ I DON'T want my blog to have a different url structure. like http://somedomain.com/blog/2010/02/article-name Any ideas on ...

What mysql query would let me get aggregated stats, by month from this table?

I have a points system setup on my site, where every single point accumulated is logged in the points table. The structure is simple, p_userid, p_points (how many points accumulated during this action), and p_timestamp. I wanna display top 3 point accumulating users, for each month. So essentially, it should sum the p_points table for...

How can I use "Dependency Injection" in simple php functions, and should I bother?

I hear people talking about dependency injection and the benefit of it all the time, but I don't really understand it. I'm wondering if it's a solution to the "I pass database connections as arguments all the time" problem. I tried reading wikipedia's entry on it, but the example is written in Java so I don't solidly understand the dif...

PHP Session expire event

Hi, I am trying to make some changes to an opensource project. I want to keep track of when users log in and log out. Right now I change their login status in db when they login or manually log out. The problem right now is that I cannot find out if the user just closed their browser without pressing on logout button. For this reason ...

What is the best practice for timezone conversions?

I want to give users the option to change their timezone and display their data in that timezone. I'm currently storing a unix timestamp and would like to know what the best way to handle this conversion would be. I am storing my timestamp in unix format. My concern is what function can I use to do the conversion on the presentation l...

Can I insert PHP variables into a JSON string?

I am using a REST API to POST attributes to a person using json. My request body looks like this: $requestBody = ' { "attribute": { "@id": "", "@uri": "", "person": { "@id": "222", "@uri": "https://api_name_removed.com/v1/People/222" }, "attributeGroup": { ...

Directly accessing server database via Ajax (without PHP or some other intermediate)

With powerful frameworks like jQuery, it seems to be possible to build an entire app logic on the client side. It's very much analogous to building a client app as a native program. Now suppose this client app needs to access a remote database. The usual solution seems to involve the layers Ajax/PHP/MySQL. It seems to me that the PHP l...

I installed XAMMP on my machine, where do I have to put my HTML files to view them?

If I enter 'localhost' on my browser, I'm taken to XAMPP's welcome screen so everything is installed correctly. What folder do I have to put my html files in? Thanks. ...

Trouble using strlen method and another newbie question.

Here's my PHP code: <html> <Head> <?php $FirstName="Sergio"; $LastName="Tapia"; $firstNameCount=strlen($Firstname); ?> </Head> <body> <h1>It works!</h1> <?php echo("Why hello there Mr. "); echo $FirstName . " " . $LastName; ...

matching the individual words from array

// I am working on matching the individual words from array $frequency // to the search results from that individual word. I don't know why this does not work for ($i = 1; $i <= ($frequency); $i++) { echo $i; echo getphp_AlexVortaro ($frequency[$i]); echo getphp_Smartfm($frequency[$i]); print_r($frequency[$i]); ...

How to backup magento to another installation

How do i get all the info, products pics, settings, etc... from one magento install to another? The backup feature it has don't seem to be that great. ...

Weird behavior calculating timezone difference

I can't explain this. I have the following: $time += $res['timezone']; (The array equates to -5*3600 (EST)) return gmstrftime('%c',$time); When I echo $res['timezone'], I get "-5*3600" which is correct. When I put the array value in front of the time variable, I get the incorrect time. If I comment out the array value and re...

PHP Switch Nav system - how can i set it up to use 2 GET variables

I use a the following PHP switch for my navigation menu: <?php include("header.php"); if (! isset($_GET['page'])) { include('./home.php'); } else { $page = $_GET['page']; switch($page) { case 'about': include('./about.php'); break; ...

If-statement: how to pull 2nd GET variable

How do I get this to pull my 2nd variable? (I already have a switch setup) <body id="<?php if (! isset($_GET['page'])) { echo "home"; } else { $_GET['page']; echo $page; } ?>"> I have a switch statement that pulls the pages from index.php?page=##### and I have just added this part to my switch: index.php?page=####&section=#####...