Home >Backend Development >PHP Tutorial >php code to get the text in the hyperlink
This article introduces a piece of code in PHP to obtain the text content in a hyperlink. It can extract text content from any link. Friends in need can use it as a reference.
The code shared in this article uses PHP regularization to extract text from hyperlinks. For example, you can get the text content from Link: Link. The code is as follows: <?php /** * @从超链接中提取文本 * @param string $url * @return string * @edit bbs.it-home.org */ function getUrlLinkText($url) { /*** find the link test ***/ preg_match('/\>(.*)<\/a>/', $url, $matches); /*** return the match ***/ return $matches[1]; } /*** example usage ***/ $url = 'Url Text Link Here'; echo getUrlLinkText($url); ?> Once again, I feel the power of PHP regularity. Friends who are interested can also expand on it to achieve more powerful functions, such as extracting links, extracting image links, extracting text in image links, etc. |