php - finding occurrence of string within a string -
i trying find out whether string contains of strings particular table of strings , assigning string found match variable , inserting said variable database. doesn't seem able find match when there match. appreciated.
this code:
$stringtomatch = 'good morning'; $string_list = "select string strings"; $resultstringlist = mysqli_query($link, $string_list) or die(mysqli_error($link)); $string_name = "test"; while ($row = mysqli_fetch_array($resultstringlist)) { if (stristr($stringtomatch, $row)) { $string_name = $row; } } mysqli_query($link, "insert table (string) values ('$string_name')") or die(mysqli_error($link));
at point, appear in table "test" in string column. ideally should insert word "morning" instead can found in table strings
stristr()
returns of haystack starting , including first occurrence of needle end.
you fetching array form query. need pass string stristr function match
while ($row = mysqli_fetch_array($resultstringlist)) { if (stristr($stringtomatch, $row['string'])) {// need pass string instead of array $string_name = $row['string'];// here pass string instead if array } }
Comments
Post a Comment