php - Looking for a specific word in a line of text on submit -


so have code: if type specific word show up, example, if ($_post['text'] word smile , convert other text $out_smile. method works when comes adding text in between text "i love smile" won’t recognize "smile" recognize "i love smile". intuitively know reason that. there way add string?

if ($_post['text'] == "smile") {      $out_smile = 'my code here <img src="url">'; } 

i want this. possible this?

 if (found in entire $text if there word == "smile") {      $out_smile = 'my code here <img src="url">';  } 

or

  $auto_detect_left = "extra text in left hand"; //i dont know how gonna   $auto_detect_right = "extra text in right hand"; //i dont know how gonna   $out_result = ".$auto_detect_left.$text.$auto_detect_right;  if ($_post['text'] == "$out_result") {      $out_smile = 'my code here <img src="url">';  } 

assuming asking verify string contained inside different string, want strpos.

$haystack = 'arglebarglearglebargle smile!'; $needle = 'smile'; $pos = strpos($haystack, $needle);  if ($pos === false) {     //$needle not present in $haystack } else {     //$needle in $haystack @ position $pos } 

please note use of ===, use mandatory in case, or not work properly. (later on should difference between == , === in php.)


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -