Is there a means to return the pattern found from within an input variable, with the possible addition of highlighting the pattern within the variable? (e.g. for Regex, returning the input variable with the pattern found)
While your question is a bit unclear, it sounds like you would like to merely highlight or mark in some form or fashion a substring (or perhaps a pattern) of a larger string. There are many ways to go about this, depending especially on the substring/pattern you'd like to search, but here's a simple example:
$input = "There is a pattern in this string. Mark the pattern.";
// There is a <em>pattern</em> in this string. Mark the <em>pattern</em>
echo preg_replace( "/(pattern)/", "<em>$1</em>", $input );
Of course this merely replaces the pattern with a modified version, returning the full string. Other functions, like preg_match
or preg_match_all
can return an array of the matched patterns. Again, it all depends on what your precise needs are.
Try using preg_match
preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )