php

Compound boolean expressions in C/PHP and variable assignment

Forgive me if the title doesn't exactly match what I'm asking, I'm having a tough time describing the question exactly. Consider the following PHP code: #!/usr/bin/php <?php class foo{ function bar() { return true; } } if (true && $a = new foo() && $a->bar()) { echo "true"; } else { echo "false"; } It give...

preg_replace PHP

I know this is really easy, and I've done it a million times myself; but it's late in the day and I have a brain meltdown. I'm trying to match and replace whole words rather than every occurance. So, I want to replace each occurance of the word 'me' and replace it with 'xxx' Ie. 'Me meets smeg' becomes 'xxx meets smeg' What I DO NOT ...

SimpleXMLElement PHP4

I know SimpleXMLElement doesn't work in PHP4, but is there a something similar I can replace it with to make the script work with PHP 4? ...

PHP explode string only if line does not end with '!'

Hi all! I'm writing a parser for a scripting programming language in PHP. The syntax of that scripting language looks like this: ZOMFG &This is a comment (show "Hello, World\!"); This is a page written in that language, that displays Hello, World! in the browser. But I could also have code like this: ZOMFG &This is a comment ! on mu...

Calling PHP Parent Constructors With Old/New Syntax.

Given the class Foo with an old-style constructor class Foo { public function Foo() { //does constructing stuff } } Is there any functional difference between calling the parent constructor with a new style constructor or the old style constructor? class Bar extends Foo { public function Bar() { //does it matter? //parent:...

checking to see if data exist with in a table

How do i go about looking into a table and searching to see if a row exist. the back gorund behind it is the table is called enemies. Every row has a unique id and is set to auto_increment. Each row also has a unique value called monsterid. the monster id isn't auto_increment. when a monster dies the row is deleted and replaced by a new...

In Doctrine, where should I put my own methods?

Let's say I have a User model. Would I put methods on the model itself, or as a template so I can access it from the user table object? In other words, which is more preferable: $u=new User(); $u->register($username, $password, $email); or $userTable = Doctrine::getTable('User'); $userTable->register($username, $password, $email); ...

php regex to read select form

Hi, I have a source file with a select form with some options, like this: <option value="TTO">1031</option><option value="187">187</option><option value="TWO">2SK8</option><option value="411">411</option><option value="AEL">Abec 11</option><option value="ABE">Abec11</option><option value="ACE">Ace</option><option value="ADD">Addikt</op...

What should every web developer know about encryption?

I've just landed a PHP5 gig. I won't be handling the parts of the application that involve super sensitive data, but I still know embarrassingly little about security and encryption methods. I only know the very basics (don't store passwords in plaintext, don't allow users to run code using post data, etc). What do I need to know to keep...

Questions regarding PHP and mootools

My question is how to pull the username into the confirmation popup... would I have to change the way my php is generating the list of users or would it need some mootools coding to select the parent and then the username... if so how could I achieve that? I have my PHP code using codeigniter to generate the following kinda things which...

Archive Template in Wordpress

Hello, I want to create an archive page template for Wordpress that will look like this: August 2009 Post 4 Post 3 Post 2 Post 1 July 2009 Post 2 Post 1 So, basically, I want all the posts from the blog, ordered descending by date and grouped by month. Can someone provide me the PHP code for this? Thanks! PS: Wordpress versio...

identify tense in php

Hi, I'm looking for a way to analyze a string of text and find out in which tense it was written, for example : "I'm going to the store" == current, "I bought a car" == past ect.. Any tips on how I could this done? ...

Uploadify won't upload files to my php script!

I'm trying to get uploadify to send it's files to a php script but it comes back blank every time... i'm totally confused as sometimes it won't even attempt to upload the files. Form: <form action="upload.php?1" method="post" id="uploadForm" enctype="multipart/form-data"> <input type='file' name='uploadBox' id='uploadBox' /><br/> <inpu...

How do I write Smarty Block Plugins that loop over database records

Given a Category (parent) and Product (child) tables in a database, say, I want to create Smarty Block Plugins that would enable template snippets similar to this: {products category="Some Category"} <h1>{products_name}</h2> <p>{products_description}</p> {/products} I believe plugins like these would help avoid repeated chunks...

Conditionally setting a javascript function after posting of a form

Apologies for the very basic question - crash course in javascript coming up! But before that, I have a javascript function: function toggle(request) The function simply toggles a div as visible/invisible. I can trigger the behaviour I want from this function using an onclick event as follows: <input type="radio" name="complete" val...

Ajax with PHP and XML, getElementsByTagName IE issue

I'm having an issue with getElementsByTagName in IE (7 and 8). I have an address lookup that returns each suggested address (as a string of XML) into a PHP session variable, which is then accessed using an AJAX function that returns the requested session variable. Each session variable is set in step 1 of the ajax address lookup (I ha...

PHP strtotime() outputs nothing

Here is my PHP code: echo '<br />1. '.$w_time_no; echo '<br />2. '.strtotime($w_time_no); echo '<br />3. '.date('G:i', strtotime($w_time_no)); That's what I get: 1. 0000-00-00 22:00:00 2. 3. 2:00 Why strtotime() outputs nothing by itself? Is there something wrong with server settings? Server: Apache/2.2.11 (Win32), PHP 5.2.10, MySQ...

PHP Classes: when to use :: vs. -> ?

I understand that there are two ways to access a PHP class - "::" and "->". Sometime one seems to work for me, while the other doesn't, and I don't understand why. What are the benefits of each, and what is the right situation to use either? ...

VIM php omni completion

Hey, I'm trying to get php autocompletion right in VIM. Right now when I do a $blog = new Blog(); $blog-> and then hit CTRL+X CTRL+O I'd expect omnicompletion to return all the functions in the class Blog. Instead, it returns all functions for the entire project. I've built ctags for my project like so: ctags -R * Is there any way to...

Most effient way to template a multi lingual site.

I am building a English/french website and was wondering if there is a best practice for such a job. Duplicating the site and making a french and english folder with the appropriate site inside. Using PHP to swap the content with html tags. eg. if($lang=='en'): Use php to swap only the content leaving the html tags the same for both....