php

MySQL: Fuzzy text search vs joins...

I've been assigned to build a questions & answers widget for my company. Many different departments in the company will want to use this widget on various websites and they will want to filter questions based on specific and unique criteria. The battle here is scalability vs efficiency. Should I: A) Make unique mapping tables in the ...

Livesearch function with JSON

Hi all, I currently have a method whereby there is an <input type="text" id="politician" name="politician" onkeyup="showResult(this.value)" value="Enter a politician's name"/> tag. In that same file that includes the input tag, there is a link to an external javascript file called ajax.js The contents of that file are as follows:...

Add ellipsis to end of truncated string in WordPress plugin

I'm trying to add an ellipsis to the end of the truncated strings this php function produces. It's part of a Wordpress plugin. But alas, I'm just learning php.... I've tried printing the ellipsis right before the ending html tag near the end of the function, like this $truncate .= '... </' . $tag . '>'; but no luck. Any ideas? It must...

How to break queries using regex in php

Suppose I have the following string: insert into table values ('text1;'); insert into table values ('text2') How do I break those queries (get each individual query) using regular expressions? I've found a very similar problem: http://stackoverflow.com/questions/958095/useregex-to-find-specific-string-not-in-html-tag ...but it uses...

How to test a custom Zend_Form with PHPUnit?

Does anyone have an example of how to test a custom Zend_Form that extend from that class with PHPUnit?? I may need to test the construct and the init... where i'm adding elements to the My_Custom_Zend_Form. ...

How to pull out Object ID in mongodb and search against it?

Please note, "user_id" in my plans collection is NOT an object_id. I have it stored in the plans collection to reference the user's _id in the user_accounts collection. I thought about storing usernames across all collections in order to reference the user, but that wouldn't be idea should the user wishes to change his/her username. // ...

PHP: using variable in another switch case.

Yes i have this line in my first "upload" case of the switch: $file_name = $USER . "-".rand(1, 888).".jpg"; Then in my switch case "crop" (that takes care of the image you crop), I wish to replace the uploaded one with the new one, simply by uploading with same name. Now i cant use $file_name in the case "crop" so how can I do this? ...

How to use variables from one PHP file in another file's function?

NOTE: I have read about 25 questions thus far that are peripherally related to this, but never answer the question directly of HOW TO USE THOSE VARIABLES CORRECTLY. I apologize if it sounds like a duplicate. I am rewriting a flat e-commerce site (all hand-made.htm files!) so that some of the pages are generated using PHP scripts. This i...

Characters replace ... need help

Hello there i am looking for a function to replace each character from a string with a rand character from array. lets say that i have a string $s="Abc"; and i have an arrays for each character like $sr[1]=array('ÀÂÁÃÄÅĀĂĄДàáâãäåāăąǻα@'); $sr[2]=array('ßβЂБЪЬб฿'); $sr[3]=array('ÇĆĈĊČćĉċς'); how can i change the $s string...

Tracking unique visitors only?

Currently I have a file called "hits.php" and on any page I want to track page hits I just use <?php include("hits.php"); ?> How can I track unique visitors only though? My hits are false since it can be refreshed by the same person and hits go up. Here's my source: <?php $hits = file_get_contents("./client/hits.txt"); $hits = $hit...

Single text field for database query

I need to be able to enter any the following types of information into into a single text field. customer name (ie first and last name). customer phone number. (including area code) customer email address. customer service ticket number. customer product serial number. How it works so far is that I have 5 different PHP files on...

Limit download speed using PHP

I found on Google some PHP scripts to limit the download speed of a file, but the file download at 10 Mbps or if it download at 80 kbps as i set it, after 5 mb, it stops downloading. Can some one tell me where I can found a good PHP download speed limit script please? Thank you very much --- Edit --- Here is the code : <?php set_tim...

PHP Count Logged-In Users

Hello, I'm having trouble figuring out how I can count the number of logged-in users in my application. What I have: When a user logs in, they get a session (which is used when the user wants to visit a protected page) and the IsLoggedIn column for the user in the users table is set to 1 to indicate that the user is logged in. When the ...

Alternative to base64_encode

Are there any other encoding functions other than base64_encode for encoding text in PHP? Edit: The purpose of the encoding functions: To generate a string that can be used in a URL that can be used as an identifier. For example, instead of http://www.something.com/?id=4&amp;category=books&amp;type=20 I would like to have: http://w...

Creating Multidimenional Arrays

How can I add arrays into an existing array item? For instance: $user[$user->id] = array(//values); But if that user needs another array added, I want all data to fall under that user ID in the array. I want to store orders a user has made, so I can look up all orders on the fly by user ID in the $user array above. ...

howto get php PDO QUERY resultset in single array instead off nested in one

I needed to change a query into a JOIN of two tables. $q = "SELECT * FROM table1 AS a JOIN table2 AS b USING(id) WHERE a.id= $id"; $stmt = db::getInstance()->prepare($sql); return $stmt->fetchAll(PDO::FETCH_ASSOC); All off the sudden I cannot refer to each row value with $rows['value'] ,BUT I need to use $rows[0]['value']. How can I ...

Get option value AND text with PHP

Let's say I have a HTML form: USA CDN And I select option 1 (USA) Then a php page Ok, duh, works fine and echo's "1" How can I display "USA" as well? So in essence, I want to pass along the option's TEXT also. How could I do this? ...

What is the PHP equivalent of Javascript's Date.UTC command?

How can I say this Javascript in PHP: var ts=Date.UTC(1985,1,22); Thanks in advance. ...

window refresh problem in php

i am using three text button and Add fourth text button after the first three text button values are refresh, this is my problem.i want four text button values plz help me ...

Wrong variable being passed in PHP form

Here is my code: echo "<table class='forum'> <tr> <td class='forum'><b>Enter Response Here:</b></td> </tr> <form action='a_insert.php?id=" . $answerid . " method=post> <tr class='forum'> <td class='forum'><textarea rows='5' cols='80' name='cBody'></textarea></td> </tr> <tr class='forum'> <td><input type='submit' value='submit'></td></tr...