Edit: Since you can't identify what part of the input string is the company name, you need to check your existing values for company_name in your table against the string. For example, in PHP:
$input = 'Somebody has sent item to "stack-exchange"';
$result = mysql_query('SELECT company_name FROM table');
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if strpos($input, $row['company_name']) === False {
print "Company name is not in this row!" /* Substitute whatever action you want here */
} else {
print "Company name is in this row!" /* Substitute whatever action you want here */
}
}
Dealing with User Input
Make sure that the input is sanitized before including it as part of a SQL query. Otherwise you make your code vulnerable to hacking.
Unfortunately, since some of the strings you receive are inputted by users, you can't be sure that they'll match what you have in your database. For example, "stack-exchange"
could reasonably be represented as "Stack Exchange"
, stack exchange
, StackExchange
, etc. So you'll need to standardize the input to match the way you store company names in your database. For example, you could make all characters lowercase and replace all spaces or punctuation with hyphens. This doesn't rule out edge cases like incorrect or variant spellings, but that's beyond the scope of this question.
If the third-party strings you receive reliably contain the company name in double quotation marks (and double quotation marks are not used to indicate anything else in those strings), you can retrieve the company name using PHP. Then you can use a SQL WHERE
clause to get the relevant rows.
$input = 'Somebody has sent item to "stack-exchange"';
$parts = explode('"', $input);
$company_name = $parts[1];
$sql_query = 'SELECT * FROM table WHERE company_name="' . $company_name . '"'