Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm stuck with this problem which seems relatively simple. I have a table full of product id numbers stored as variable $partnumber. When processing changes in inventory I need to know if an entire $partnumber string is within another $partnumber string.
For example, I need to know if PRA-LGL70-B2-BKWH-EC-L69A7330 exists within other variable strings such as the ones below.
PRA-LGL70-B2-BKWH-EC-L69A7330
PRA-LGL70-B2-BKWH-EC-L69A7330-L6901
PRA-LGL70-B2-BKWH-EC-L69A7330-L6901-L5156
There are tens of thousands of these partnumbers in a table and I've been told that preg_match might be too slow. Unfortunately, I cannot change the actual data so the only potential delimiter is "-". I'm sorry that I don't have any source code because I just started on this problem. Can anyone point me in right direction?
Without more details it is hard to know the requirements of your problem. As mentioned in the comments, it is probably better to do this in the database. But to directly answer your question - PHP - Searching for a variable match within another variable use strpos():
$partnumber = 'PRA-LGL70-B2-BKWH-EC-L69A7330-L6901';
$search_for = 'PRA-LGL70-B2-BKWH-EC-L69A7330';
if (strpos($partnumber, $search_for)!==false)
echo "Match found";
Note: stripos() will do the same thing, but will not consider case.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a data set of searches made on a website. I have to find top searches from that data set. The problem is, i cannot think of a way to do it. The search terms are long sentences. How could i find what are users interested in? It seems to be a problem of counting and i am using php. Any suggestion would be appreciated.
You can create a table in database, which will contain columns search_phrase and counter. Each time when user will search same phrase, you'll just increase counter instead of creating new row.
You can also create a script which will take all records from this table, and find similar phrases.
You can make counter corresponding to each phrase. Suppose You have a queries in long sentence format , divide your sentence into smaller parts and identify the most meaningful word and avoid the conjuctions and other verbs. Particularly focus on Nouns. For an eg, Query is : How to Make account on stackoverflow? Possible Solutions[words] : account, stackoverflow,make. Possibly in this way you can solve it.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am writing a small program where I want to extract user input strings from MySQL database. But I am not looking for exact matching strings. For example
If user types amazon then it should extract amazon from the database. But if user types amazonn or amazo or amozon it should still retrive amazon because it is the nearest word to the misspelled word.
This is something similar to google suggestions while searching. Is there anyway to define a function like this in PHP? Do i have to import dictionary and compare with it?
You could use strpos() in two ways
How do I check if a string contains a specific word in PHP?
Search for the DB string in the string that the user inputted.
And the other way around:
Search for the string that the user inputted in the DB string.
The problem with this is that you only cover differences at the outside of the string
such as amazo or amazonn but not amozon
Or you could use levenshtein() and similar_text() as stated in the comments.
Good example code with suggestions:
https://codereview.stackexchange.com/questions/27173/php-spell-checker-with-suggestions-for-misspelled-words
That should be covered in an entirely different way...
I think you want both checks but everything is going to be difficult without a dicitonary so I suggest importing one ;)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I got input type field and value in that field is changing when I move bar on range slider.
Can someone help me to write some if condition.
I want when the value is 1 to echo "one"... when value is 2 to echo "two"...
here is range slider and input type="text" with values.
link to page I am trying to do :)
Thanks!
bored enough to bother:
$out=array('1'=>'one','2'=>'two'); //etc
echo $out[$_POST['selected']];
Your question, as phrased, is going to be difficult to answer. Here's why:
You are working with an interaction between an HTML web form and a PHP script. However, you didn't provide any example code, so it's impossible to know how you are setting up this interaction.
It might be better to approach this purely as a javascript or jQuery solution - but without knowing what you are doing with the end result, it's impossible to make that judgment or offer guidance.
If you are hoping for a strict PHP solution, how would you like the data returned - if you need it returned at all. A PHP script to do what you ask is fairly simple - but the return portion can be involved.
Perhaps you're simply looking for the PHP switch statement?
Are you actually trying to convert an int or float to it's string text? Take a look at this answer...
Finally, you might want to review the write-up on asking questions. You'll get better answers.
mnr
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
You find a lot of info on this online. But not what the exact work around of the use of Algorithm is in MySQL. The real basics, if you will..
What a query is, is obvious, of course. What Algorithm does, remains unclear.
Main reason for this question is: to improve profiling & matching records to known users. (In this case: to match docs in a database to users that need them)
Some examples of the usage of it are highly appreciated!
Algorithm is a keyword used with create view in MySQL. The documentation does a pretty good job of explaining it.
The short answer is that MySQL supports two methods of handling views: either "merging" the view definition in the calling code or creating a temporary table. The first is called MERGE and the second TEMPTABLE. In general, MERGE is faster, but most views are TEMPTABLE because of the restrictions on `MERGE.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In my php code, I am writing a class to create log files, and therefore have to work with files. I would like to store the variable $handle as a field, however when I refer to it as $this->handle, "handle" changes color, to indicate that perhaps it is a reserved term.
I looked through the php manual as well as some other online sources and haven't found anywhere saying it is actually reserved. Can someone clear this up for me?
Thanks for your help.
Cheers!
------------- Edit ---------------
It looks like it's recognizing handle as at least 3 static methods...still not sure what the "K" word means. Key?
Not only is it not reserved, but it is a common convention to call resource IDs and more $handle. In fact, you can find it throughout the PHP documentation. For example, fopen.