php

Is there a, kind of, 'Crystal Ball' OOP Design Pattern?

With regards to design patterns such as GoF, is there a pattern to decribe when one object needs to observe another object that is not even in existance yet? i.e. $crystalBall = new crystalBall(); $futureDependent = new FutureDependent(); $futureDependent->attach($crystalBall); ... then much later .... $importantObject = new Importa...

How to create .po files using xgettext on Windows?

I'm following this tutorial about building a multilingual web sites using PHP gettext http://onlamp.com/pub/a/php/2002/06/13/php.html I understand the tutorial until this part: After you have the directories all prepared, it's time to create the actual "pot" file, as it is usually referred to: the messages.po file. To do th...

PHP date format question

I'm trying to format some dates in PHP (i'm a Coldfusion programmer, so the syntax is similar, but i'm stuck!). The dates are formatting perfectly into the display I want. However, they all return 1st Jan 1970. Can anyone shed any light on this? For background, I am pulling a date from a datetime column in mySQL. The raw date i'm tryi...

Kohana: Is it necessary to check if SYSPATH is defined?

I'm a CodeIgniter user and I'm taking a look at Kohana. First thing I noticed is that in the documentation every snippet starts with: <?php defined('SYSPATH') or die('No direct script access.'); assuming I'll be using .htaccess for address rewrite, is this really necessary? Is it an alternative to .htaccess for the purpouse of avoidin...

How do I build a dynamic SQL query?

Right, so I have a set of dropdowns on my page. Depending on whether a value is selected, I want to add it to an SQL query string in PHP. Example: select1: options("*" "op1", "op2) select2: options("*" "op1", "op2) select3: options("*" "op1", "op2) '*' refers to anything. i.e the data should not be filtered by that query option. Now, ...

php5 encoding problem turkish characters

i have a php script which detects keyword density on given url. my problem is, it doesn't detect turkish characters or deletes them.. i'm getting contents of url by file_get_contents method. this method works perfect and gets all content with turkish characters. you can see my code on http://www.gazihanisildak.com/keyword/code.txt ...

Conditional php_flag statements in .htaccess

Is there a way to conditionally execute php_flag statements in .htaccess? Here are two things I'm trying to do: Turn error reporting on if the client's IP address matches the IP address I use: if %{REMOTE_ADDR} == '12.34.56.78' then php_flag error_reporting 1 else php_flag error_reporting 0 Turn off register_globals if the IP a...

PHP secure downloader with PayDotCom or Paypal

The script below is a quick and dirty attempt to provide a means of protecting my files that I'm selling on PayDotCom and Paypal. If anyone has experience with these services, I have a few questions... 1) Is there a token that I can set at either of these pay sites that I can then check for in the script below before executing the down...

Select date/time groupings in MySQL grouped by hour

I have a bunch of date data in a mysql table like this: 2010-02-13 1:00:00, "soma data" 2010-02-13 1:25:00, "soma data" 2010-02-13 1:37:00, "soma data" 2010-02-13 2:12:00, "soma data" I want to select a report which shows the data grouped by hour, for example: On Feb 13, during the hour from 1:00 pm to 1:59 pm, there were 3 data poin...

PHP Foreach array as a error in function (invalid argument for foreach in...)

Im working on a new minimal Project, but i've got an error, i dont know why. Normally, i use arrays after i first created them with $array = array(); but in this case i create it without this code, heres an example full code, which outputs the error: <?php $i = array('demo', 'demo'); $array['demo/demodemo'] = $i; ?> <?php $i = array('...

Correct Procedure for mysqlConnect

Hello, I am new to php syntax and am looking for advice on creating the most acceptable or correct code. I focus on front end design, but I like to make sure my code is proper. I am in a digital media program, my instructor has given us this code for connecting to our MYSQL databases. <?php mysql_connect("localhost", "root", "root")or d...

I'm learning PHP on my own and I've become aware of the strip_tags() function. Is this the only way to increase security?

I'm new to PHP and I'm following a tutorial here: Link It's pretty scary that a user can write php code in an input and basically screw your site, right? Well, now I'm a bit paranoid and I'd rather learn security best practices right off the bat than try to cram them in once I have some habits in me. Since I'm brand new to PHP (litera...

PHP work with JS Jquery

Hello. How do i make PHP work with JS? I mean more like, i want to check if the user is logged in or not, and if he is then it will: $("#message").fadeIn("slow"); .. How should i do this? I have an idea maybe have a file that checks it in php, and then it echo out 1 or 0. And then a script that checks if its getting 1 then do the me...

javascript php array

i have a js array like this: var myArray = []; myArray[1] = 'test'; myArray[2] = 'test'; -i want to hide it from users to see it. how can i store just the array in a php script and call it? right now i have the .js separate from my form. and i just call it. but anyone can easily view source and visit the url using the .js name -ano...

Trying to validate a name field to be sure it is all alpha characters or a hyphen or apostrophe

if(!preg_match("/[a-zA-Z'-]/",$First)) { die ("invalid first name");} the above only flags input as invalid when the field is all numeric. combinations of letters and numbers pass ok. Some help here for a newby please. thanks. ...

fopen not working for some urls?

I am having problems reading some urls. There is nothing wrong with the urls, as I can view them in my browser (an example of one such URL is given below): http://www.bloomberg.com/apps/news?pid=20601087&amp;sid=a2BhXFMpbb5M I am using fopen like this in my code: public static function grokPage($path) { $data = ''; $file = fop...

PHP Overloading similar to sprintf()?

How do you write a function in PHP that can accept an unlimited number of arguments similar to sprintf? sprintf("one:%s",$one); sprintf("one:%s two:%s",$one,$two); ... ...

Debugging Zend Framework project with NetBeans / XDebug

Hello, Has anyone been able to set up NetBeans debugging of a Zend Framework project? I have XAMPP running locally on my machine, as well as NetBeans 6.8. From the looks of phpinfo(), XDebug is properly installed on XAMPP. I start debugging session with NetBeans, it connects to XDebug and the page opens, however it will not stop at any ...

how to get returned text from a php page

Hi, very simple php question, for example, demo.php just returns a text like this "hello". how can i get this text from an another php page ? UPDATE: actually i meant page is outputting it like this "print 'hello';" ...

Designing/Implementing MVC from Scratch

Hi, I want to create my very first web app using HTML, MySQL, PHP and the Model View Controller. It will be very simple for starters: a couple of pages that allows users to input/delete data to/from the database and display the contents of the database. However I am new to MVC, and I really wish I could have found MVC tutorials approp...