Use a regular expression to extract URLPHP from a text segment use a regular expression to extract a URL from a text segment. The existing text is as follows: "What do pig eat? how can I extract Na from the East ?" I want to extract it to http://c.com/dkaeaa. please give me some advice. what is phpcode?str='? use a regular expression to extract a URL from a paragraph of text
PHP uses regular expressions to extract URLs from a paragraph of text
There is a piece of text like "what do pig eat ?"
I want to extract to http://c.com/dkaeaa
Please give me some ideas
------ Solution --------------------
PHP code
$ Str = 'What is the pig eating? do I need to extract this fat content from http://c.com/dkae? '; Preg_match_all ('/https? : \/[\ W-. % #? \/\] +/I ', $ str, $ matches); print_r ($ matches);/** output result: array ([0] => Array ([0] => http://c.com/dkae ))*/