用PHP检测特定单词之间的单词

for example,

<form method="post">
    <textarea name="content" id="editor"></textarea>
    <input type="submit" value="submit" name="alltext">
<form>

Then I type: Humans have ==brain== and it helps them learn things. After that, I want this thing to find the word between == and ==.

$all_text = $_POST["alltext"];
if (a word is between '==' and '==') { 
    $special_word = the word between '==' and '==';
} else {
    do nothing 
}

and the output I desire is the variable $special_word is set to brain.

It is more like stackoverflow.com where words between # and # is heading 1 and words between ## and ## is heading 2.

Please help me solve this puzzle.

You should use preg_match to get the sub-string:

$str = 'Humans have ==brain== and it helps them learn things';
preg_match('/==(.*?)==/', $str, $match);
$special_word = $match[1];

You can use this Regex to match the string, then you can simply extract it and put it into a variable.

Here is the regex:

/\w+/

You can use PHP regex function to match or extract from strings.

Here is the reference to PHP regex functions:

PHP PCRE functions

P.S: preg_match() should do well here in your scenario.

P.S: If you are trying to extract the word brain form a sentence you should use regex like this:

/==(.*?)==/