How can preg_match() be used to extract a word between two % symbols in a string?

To extract a word between two % symbols in a string using preg_match(), you can create a regular expression pattern that matches the desired word enclosed by % symbols. The preg_match() function can then be used to search the string for this pattern and extract the word. The extracted word can be stored in a variable for further processing or output.

$string = "This is a %sample% string with %words% enclosed in %symbols%";
preg_match('/%([^%]+)%/', $string, $matches);
$extracted_word = $matches[1];
echo $extracted_word;