Extract a URL from a text segment using a regular expression-php Tutorial

Source: Internet
Author: User
Use a regular expression to extract URLPHP from a paragraph of text use a regular expression to extract a URL from a paragraph of text. the existing section of text is like "c. do you know how to extract comdkae?" I want to extract it to c. comdkaeaa. please give me some ideas ------ solution -------------------- PHPcode $ str what do pig eat? what do I need so fat http use regular expressions to extract URLs 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 ))*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.