php

MySQL - Is using TEXT for potentially small strings overkill?

One of the things that always worries me in MySQL is that my string fields will not be large enough for the data that need to be stored. The PHP project I'm currently working on will need to store strings, the lengths of which may vary wildly. Not being familiar with how MySQL stores string data, I'm wondering if it would be overkill to...

What's the best practice in using if/else as a substitute for try/catch or vice versa?

Possible Duplicate: What is the advantage of using try {} catch {} versus if {} else {} I'd like to know whether, generally speaking, it's better to use a try/catch construct or to try to prevent this exception by (excessive?) use of if/else. Example: should I catch a FileNotFoundException, or should I test and try to find the...

PHP - How to return the Server Validation Message back to Client side?

Hello all, The structure of the implementation of server side validation can be adopted by the following two methods. Method one: The PHP script does the validation is the same one that provides the user with an input form. Say form_client_server.php Method one: The PHP script does the validation is different from the one that provide...

Validating actions in Symfony (PHP)

I've been reading some Symfony documentation regarding validation/error-handling for controllers. http://www.symfony-project.org/book/1_2/06-Inside-the-Controller-Layer Validation and Error-Handling Methods (just over 2 thirds down) I like the idea of a function automatically being called - validateMyAction before executeMyAction is c...

Whats wrong with this regular expression?

I have the following regular expression to find word in text and highlight them Using the word surface for testing purposes. /((?<=[\W])surface?(?![\w]))|((?<![\w])surface?(?=[\W]))/iu It matches all occurences in the following text. surface-CoP-20-70-0000-04-02_Pre-Run_Tool_Verification_Programming_and_surface_Tare surface_revC.pdf...

PHP won't echo out or execute JavaScript.

Hi guys, I need PHP to open up a new window with a text from a variable. Here's what I tried. echo "<script> $myWin=window.open('','$myWin','menubar,scrollbars,left=30px,top=40px,height=800px,width=800px'); $myWin.document.write(".$logtext."); </script>"; but it doesn't work. any better ideas or suggestions? Thanks! :) ...

mod_rewrite works for URLs with en, es but not zh-tw and zh-cn?

My sites are in 4 languages and they are accessed with the following pattern: http://example/index.php?lang=en http://example/index.php?lang=es http://example/index.php?lang=zh-tw http://example/index.php?lang=zh-cn I'm using the following mod_rewrite rule in my .htaccess file: RewriteEngine on RewriteRule ^([a-z]{2}(-[A-Z]{2})?)/(.*...

Query MySQL for permissions in PHP

I have a site where a user can have multiple permissions (view, edit, delete, create). Each of these is stored as a tinyint(1) field in the database. I'm looking for the best (quickest?) way to query MySQL to see if the user has the ability to see this page. Here is a snippet: $user = mysql_real_escape_string($user); $resultset = mysql...

How to handle non-English characters extracting from MySQL database?

I am extracting text from a MySQL database table, collation is set to utf8_general_ci. In PHPMyAdmin, I can see the characters correctly: "La consiglio fermamente anche perchè ho già acquistato iWrap per il mio:" But when I extract it myself it prints out this way: "La consiglio fermamente anche perch� ho gi� acquistato iWrap per il ...

Create txt file in PHP

Hi, I am creating text file in php, file has created in correct format from local pc and if i am trying online then no line break is there and not displaying formated. I am using this code. header("Content-type: application/txt"); header("Content-Length: ". sizeof($content)); header("Content-Disposition: inline; filename=". $file); pr...

Using same input box for search and submit?

I am working on an application where I need to use same input field for multiple functions. Searching similar queries via text box Submitting a query if none of the results interest the user If user start typing with 'comma' i:e tag1, tag2.. it should be able search for the result I am relatively new to development, community...

Multi-company web application database security

My question is very similar to this question but a bit more specific. My application has multiple companies and multiple users per company. It makes the most sense to me (at this point) for each company to have a "private" set of tables. This makes security extremely simple as I don't have to worry about JOIN-ing up my structure tree to...

Is there any way to return HTML in a PHP function? using a string

i need to return information from a php grab function in html so i can post it in my form. ...

PHP variable variables in {} symbols

I get the basics of variable variables, but I saw a syntax just know, which bogles my mind a bit. $this->{$toShow}(); I don't really see what those {} symbols are doing there. Do they have any special meaning? ...

Check if directory path ends with DIRECTORY_SEPARATOR

In PHP I'm receiving a string from the user for a local file directory $path I want to know if they've included the trailing slash (/) or not. I would like this to be cross platform so I'd like to use the PHP constant DIRECTORY_SEPARATOR My failed attempts include trying to do a preg_match like preg_match("/" . DIRECTORY_SEPARATOR . ...

mime type not found for file upload in Symfony functional test

When I run my functional tests through Symfony, the uploaded file is not being supplied with a mime type. My test case shows: $browser->info('1 - Test Upload Form')-> get('/formpage')-> setField('myform[file]', sfConfig::get('sf_upload_dir').'/example.doc')-> click('input[type=submit]')-> end ; And is executed on the command ...

Zend Decorators - Remove Id Field for DT Wrapper

Hey, I got two forms and they share some ids as two input fields are called 'title'. Zend generates me a nice output like this: <dl class="zend-form"> <dt id="title-label"> <label for="form1-title" class="required">Description</label> </dt> <dd id="title-element"> <input name="form1[title]" id="form1-title" value="..." t...

PHP: passing data through header.

hi, i'm trying to send a simple request and get response however i get response as internal error. parameters "cookie: sessionid", ipaddress and mode are all supposed to be http headers and my json request {"postcode":"EC2A 3AY", "propertyIdentifier":"93A"} <?php $json = '{"postcode":"EC2A 3AY", "propertyIdentifier":"93A"}'; $ch = curl...

Doctrine 2 configuration with MySQL

I'm busy with Doctrine2, but I can't get it to work. Everything works fine out of the box with sqlite. But when I try to change the database in the sandbox demo to MySQL I'm getting confused. This is what I did. I created a database, changed the connectionOptions array to: $connectionOptions = array( 'driver' => 'pdo_mysql', '...

How to prevent the most number of cheaters for polls?

On my website we run a contest system and users vote for other user's content. We recently caught someone creating multiple accounts to vote multiple times (consecutive id numbers, and votes within a couple minutes). We would like to prevent that from happening again. Judging how Times handled their "Most Influential Person of the Centur...