php

using php to assign one of a set of values to any input consistently

I have two input fields for example's sake called A and B. What i want, is to somehow derive a hash or total of these inputs, and pass that to a php function which will give me one of a set of results, but consistently. Heres what i think it should look like pseudo code $a = $_POST[a]; $b = $_POST[b]; $pre = "$a$b"; // Put both inp...

Rails "respond_to" in PHP

Lately I have been trying out Rails, and I came to love the respond_to. Is it possible to do something like this in PHP?, responding to different types of requests. So it is easy to implement an alternate way even if javascript is disabled. ...

How to search and replace by comparing two PHP arrays

I have this string where I've put all opening tags into (array) $opened and all closing tags into (array) $closed, like so: '<div> Test </div> <div> <blockquote> <p>The quick</p> <blockquote> <p>brown fox <span>jumps <span>over <img src="#" /> the' Results in these two arrays: $opened = array(8) {...

syntax error, unexpected $end in php

I am getting the following error in one of my php file Parse error: syntax error, unexpected $end in /home/qualitet/public_html/game/create.php on line 1 What could be the problem? I checked all the if else. ...

Is there a limit to MySQL queries?

I am trying to insert 10,000+ fields into my database? Is there a limit? $sql = 'INSERT INTO `_'.$test.'` (`user`, `pass`) VALUES ' . preg_replace($test, $replace, $final_check) . ';'; mysql_query($sql) or die(mysql_error()); Every time I try to insert the data, it fails. ...

An example of an MVC controller.. Please

I have been reading alot about how and why to use an MVC approach in an application. I have seen and understand examples of a Model, I have seen and understand examples of the View.... but I am STILL kind of fuzzy on the controller. I would really love to see a thorough enough example of a controller(s). (in PHP if possible, but any lang...

RegEx to get the keywords from HTML

I'm trying to obtain the keywords from an HTML page that I'm scraping with PHP. So, if the keywords tag looks like this: <meta name="Keywords" content="MacUpdate, Mac Software, Macintosh Software, Mac Games, Macintosh Games, Apple, Macintosh, Software, iphone, ipod, Games, Demos, Shareware, Freeware, MP3, audio, sound, macster, napste...

Site structure in PHP, with examples...Please

I've been reading about site structure in PHP, but whenever I read or ask questions about site structure, I get something like this /application /config application.ini /controllers /views /models bootstrap.php /var /log /tests /controllers /views /models /libraries /mylib ...

how to read new-line from a textarea in a form with PHP?

How can I read the New-line so that when users fill in a text-area inside my form, and then hit submit, the text is displayed exactly the same way as they wrote it? I should mention I read in the variables from the form with POST method in my php file. Thanks ...

Loops within Switch statement

my switch statement has about ten outcome, but some of them need 1/2 loops to check, so i can't write them within case(condition), so i've tried using more than one default case, is this possible? <?php switch(true) { case 1: break; case 2: break; default: echo "this text is never printed ??"; while(true) { whi...

Implementing PostgreSQL arrays in Zend Model

Couldn't find anything related to the subject in Zend Framework API. What is the best way to implement Postgres array based property into Zend Model Class? I know one can parse array from "{ smth1, smth2 }" like string, but I still hope that there is more unattended approach in Zend case. Thanks. ...

automatic line-break of textarea inside a form possible with PHP?

I know about the nl2br function... But is there a way to set a maximum length of a line? Im using php to get results from a form, which contains a textarea. I dont want words to get broken to newlines, like the word 'example' to become 'example' Thanks ...

Precision loss whilst inserting a double into MySQL through PDO

Hi All, I've run into this really annoying behavior and I want to know if I'm doing something wrong, or if this is intentional (and if so, why). Whenever I have a variable in php (5.3) that is of type double and I want to insert it into the database (MYSQL 5.0) in a field that is of type double, the value always gets rounded down to 6 ...

[PHP] Dynamic GD image width text

I'm trying to spice up my website by using custom fonts for headings. For me, the most appropriate way to do this is using PHP and GD. I have written a little script which will output the dynamic text based on the $_GET value, however sometimes the image is too wide, which moves everything else about. How can I get the image to adjust t...

little more help with text-area wrapping...

$ad_text=wordwrap(nl2br($_POST['annonsera_text']), 45, '<br />\n'); Any idea why the above does display in a long string? Form method='POST', and enctype='multipart/form-data' and textarea wrap='hard' I want the displayed text-area to look exactly the same as when the user entered the text in it... thanks... UPDATE: aaaaaaaaaaaaaaa...

Declaring an Array using Variables and the array() construct in PHP

I'm sure this has been asked before but I can't find it. The PHP documentation unclear on this and I can't find any examples like this. Is it legal to use variables in the declaration of an array use the array() construct? Not as keys, as the values. Like this: function myFunc($value1, $value2, $value3) { $myArr = array('value1'...

Get Text UIWebView PHP script

Basically my app has a UIwebView which loads a php script with input of user data. The script then uses printf(some info). This all works and it prints it right the UIWebView. Basically what I want to do is get that text (its all thats on the page) and save it as a string. Heres what I have tried so far. NSString *str = [webView stringB...

Using ReflectionMethod::invoke in a context when original object is not in scope

I'm trying to do something like this: class A { public function foo() { $b = new B; $b->invokeMethodFromAnotherObject(new ReflectionMethod($this, 'bar')); } public function bar() { } } class B { public function invokeMethodFromAnotherObject(ReflectionMethod $method) { $method->invoke(?); } } But...

Generate unique names???

I am working on a php site in which we have to upload images from users.i have to rename that file for preventing conflicts in the name of the image. uniqid(rand(), true); and adding a large random number after it. Will this work perfectly. Any suggestions..?? Its about generation unique names for the image..... ...

Attaching a stylesheet with dirname(__FILE__) won't work even though the file is there.

Hi. I have a PHP class that creates a header for my html file.. It's included, and that file is included again.. So I thought that the dirname(__FILE__) function could work.. But it says it can't find the stylesheet.. I'm using mamp on os x, and when I take the path that I get from dirname(__FILE__)./../stylesheets/stylesheet.css into t...