Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

# Untitled

By: a guest on Sep 5th, 2012  |  syntax: PHP  |  size: 0.90 KB  |  views: 70  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. <?php
2.
3. \$input = "one two three";
4. print "\$input => ".expand_to_sphinx_query(\$input)."\n\n";
5.
6. \$input = "one two three four";
7. print "\$input => ".expand_to_sphinx_query(\$input)."\n\n";
8.
9. \$input = "one two";
10. print "\$input => ".expand_to_sphinx_query(\$input)."\n\n";
11.
12. \$input = "one";
13. print "\$input => ".expand_to_sphinx_query(\$input)."\n\n";
14.
15.
16. function expand_to_sphinx_query(\$input) {
17.         \$words = explode(" ",\$input);
18.
19.         if (count(\$words) < 2) {
20.                 return \$input;
21.         }
22.
23.         \$bits = array();
24.
25.         for(\$q=0;\$q<count(\$words)-1;\$q++) {
26.                 \$new = \$words[\$q].' '.\$words[\$q+1];
27.                 \$bits[] = "\"\$new\"~2";
28.                 \$bits[] = "\"\$new\"~50";
29.                 \$bits[] = "\"\$new\"";
30.         }
31.
32.         if (count(\$words) > 2)
33.                 \$bits[] = "\"\$input\"";
34.         \$bits[] = "(\$input)";
35.
36.         return implode(' | ',\$bits);
37. }
clone this paste RAW Paste Data
Top