0

I am trying to figure out how to search in php for substring. When I tried using this:

while ($row = db_fetch_array($results)) {
if(strpos($row['field_rep_contact_name_value'], $get)) {
  $names['suggestions'][] = $row['field_rep_contact_name_value'];
}
}

I found that when the $get value was 'arm', it returned true for strings which had 'ar', I only want it to return true if it contains 'arm', the full value of the $get variable. I think this can be done with regex but not exactly sure how.

1
  • are you saying that you want to find if $get is contained in $row['field_rep_contact_name_value'] or if they match exactly? Commented Sep 18, 2014 at 16:48

1 Answer 1

2

Add a !== false to your statement

$stringone = 'lucas vieira';
$stringtwo = 'luca';

strpos($stringone, 'lucas') !== false // returns true

strpos($stringtwo, 'lucas') !== false // returns false
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.