Home > Backend Development > PHP Tutorial > How to extract website url address in string in php, string url_PHP tutorial

How to extract website url address in string in php, string url_PHP tutorial

WBOY
Release: 2016-07-13 10:12:16
Original
1022 people have browsed it

php method to extract website url address in string, string url

The example in this article describes the method of php extracting the website URL address in the string. Share it with everyone for your reference. The specific analysis is as follows:

After I wrote a question and answer system today and went online, I found that many people posted links. Since the business department asked us to filter out website addresses, I will share with you a function to extract string url addresses. The code is as follows:

Copy code The code is as follows:
$postInfo['answer2'] ='Yes, commercial loans can be amortized at 36%, and provident fund loans can be amortized 16% repayment|||You can withdraw the balance in the account first and use it as a down payment, and then the monthly loan can be amortized at 36% for commercial loans and 16% for provident fund loans|||Yes, now Class A provident fund is The amortization ratio http://www.bkjia.com is 34% of the salary base |||Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhsssssssssssssssssssssssssssssssssssssss of ';

preg_match_all("/http:[/]{2}[a-z]+[.]{1}[a-zd-]+[.]{1}[a-zd]*[/]*[A-Za- zd]*[/]*[A-Za-zd]*/",$postInfo['answer2'],$array2);

print_r($array2);

if(!emptyempty($array2[0]))
{
foreach ($array2[0] as $k=>$v){
$postInfo['answer2'] = str_replace($array2[0][$k],'',$postInfo['answer2'] );
}
}

The running result is:

Copy code The code is as follows:
(
[0] => Array
(
                                                                [0] => http://www.bkjia.com
)
)
I hope this article will be helpful to everyone’s PHP programming design.

http://www.bkjia.com/PHPjc/920983.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920983.htmlTechArticleHow to extract website url address in string by php, string url This article describes the example of php extracting website in string URL address method. Share it with everyone for your reference. The specific analysis is as follows:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template