I have a string in php example below.
$ string = "This is my website example.org Check it out!"; If (preg_match ('/ \ w + \. (?: Com | org) / i', $ string, $ match)) {var_dump ($ matches [0]); Echo '' $ matches [0] ''; } This will echo out
string (11) "example.org" example.org I only
example.org
You only need one echo to do this Regular expression for here is a beginner:
$ string = "Check it out my website is example.org!"; If (preg_match ('/\w+\.((:::com-org) / i', $ string, $ matches)) // // var_dump ($ matches [0]); // resonant '& lt; a href = ''. $ Matches [0]. '' Gt; '$ matches [0]' ' < P> regex is: \ w + \. (?: Com | org) ^ ^^ | | matches the organization or organization | Match one term one or more words Characters [A-Za-z0- 9_] This:
string (11) "example.org" You must customize it to include subdomains and protocols when necessary.
Comments
Post a Comment