php

PHP/MySQL update a news record in a database problem

I have this PHP code that I am trying to use to let a user edit a news record in a form and then when they hit the submit button, it will update the record in a database. The problem is that everything works but the record is not actually updated in the database. Could someone look at my code and see where a problem could occur? <?php ...

Don't wait for the process to exit

I have a PHP script that is called from a cron job every minute. This script takes some info from the database and then calls another PHP script using the System function (passing it some parameters). That means that I can start up to 10 scripts from this "main" one. And what I would like to do is that I would call the script and contin...

PHP regex to remove multiple ?-marks

I'm having trouble coming up with the correct regex string to remove a sequence of multiple ? characters. I want to replace more than one sequential ? with a single ?, but which characters to escape...is escaping me. Example input: Is this thing on??? or what??? Desired output: Is this thing on? or what? I'm using preg_repla...

Format mysql datetime with php

I got a datetime column in mysql which I need to convert to mm/dd/yy H:M (AM/PM) using PHP. ...

Suppress error with @ operator in PHP

In your opinion, is it ever valid to use the @ operator to suppress an error/warning in PHP whereas you may be handling the error? If so, in what circumstances would you use this? Code examples are welcome. Edit: Note to repliers. I'm not looking to turn error reporting off, but, for example, common practice is to use @fopen($file); ...

Php redefine Class Methods OR Class

Is there any way to redefine a class or some of it's methods without using typical inheritance ex: class third_party_library { function buggy_function() { return 'bad result'; } function other_functions(){ return 'blah'; } } what can I do to replace the buggy_function? Obviously this is what i would lik...

PHP Object as XML Document

What is the best way to take a given PHP object and serialize it as XML? I am looking at simple_xml and I have used it to parse XML into objects, but it isn't clear to me how it works the other way around. ...

Three table related model in CakePHP

I've got a CAkePHP 1.2 site. I've got three related Models/tables: A Comment has exactly one Touch, a Touch has exactly one Touchtype. In each model, I have a belongs to, so I have Comments belongs to Touch, Touch belongs to Touchtype. I'm trying to get a list of comments that includes information about the touch stored in the touchtyp...

How do I prevent using the incorrect type in PHP?

PHP, as we all know is very loosely typed. The language does not require you to specify any kind of type for function parameters or class variables. This can be a powerful feature. Sometimes though, it can make debugging your script a painful experience. For example, passing one kind of object into a method that expects a different kind...

Null vs. False vs. 0

I am told that good developers can spot/utilize the difference between Null and False and 0 and all the other good "nothing" entities. What is the difference, specifically in PHP? Does it have something to do with ===? ...

How can I set what encoding must be used by a site?

On some systems it is UTF-8, on others latin-1. How do you set this? Is it something in php.ini? (I know you can set the encoding/charset for a given page by setting HTTP headers, but this is not what I am looking for.) Alex ...

How do I upload a HTML form with a username, password, multiple file uploads and then process it with PHP?

How to post a username, password and multiple binary files from a single html form and process it using php? I'm not allowed to use ajax. ...

PHP alias @ function

I'm new to PHP and I'm confused seeing some examples calling a function with a @ prefix like @mysql_ping(). What is it for? Googling / searching is not much of a help since @ gets discarded and 'alias' is not good enough keyword. ...

How would you go about auto-detecting Textile versus Markdown?

I'm considering supporting both Textile and Markdown on a current project. I would prefer not forcing users to choose one or the other. Is there a way to auto-detect which the user is using? How would you go about this? I'd like to find / develop both a JavaScript and a PHP solution so I can provide live previews as well as process the u...

How to extract img src, title and alt from html using php?

I would like to create a page where all images which reside on my website are listed with title and alternative representation. I already wrote me a little program to find and load all html files, but now I am stuck at how to extract src, title and alt from the html < img src="/image/fluffybunny.jpg" title="Harvey the bunny" alt="a ...

PHP: close a connection early

I'm attempting to do an AJAX call (via JQuery) that will initiate a fairly long process. I'd like the script to simply send a response indicating that the process has started, but JQuery won't return the response until the PHP script is done running. I've tried this with a "close" header (below), and also with output buffering; neither ...

MVC, where do the classes go?

My understanding of the MVC is as follows (incase it's horribly wrong, I am afterall new to it) Models are the things that interface with the database Views are the design/layout of the page Controllers are where everything starts and are essentially the page logic I'm using CodeIgniter but I would hazard a guess it's not just limite...

PHP Class Database Connection Scope Issue

For a new project that I'm doing in PHP I've created an SQLMethods class to connect to the database and perform queries. Tonight was the first night that I actually got to test it (I wrote it a week or so ago and forgot about it) and an unexpected error occured: When it was calling my ExecuteQuery() function, it wouldn't use the database...

How unique is the php session id

How unique is the php session id? I got the impression from various things that I've read that I should not rely on two users never getting the same sessionid. Isn't it a GUID? ...

Which Coding convention to follow for PHP?

Should I stick with Sun's Java code conventions for PHP code? ...