Search code examples
phppreg-match

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?


Solution

  • 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.