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
Post a Comment