S.Macualiff S.Macualiff - 1 month ago 5
PHP Question

how to display matches characters in preg_match

I'd like to string matching with regular expression by using preg_match() This is my code

<?php
$string = preg_match("/http\:\/\//","http");
echo $stirng;
?>


That is working well. But i want to display that what is the matching characters. how to do that?

Answer

Use $matches another parameter inside the preg_match function. Like this

<?php
preg_match("/http\:\/\//","http://",$matches);
// this $matches echo out as a array object then,
print_r($matches);
?>

I hope this will work.