convert url to links from string except if they are in an attribute of an html tag

后端 未结 4 2067
我在风中等你
我在风中等你 2020-12-16 01:21

I am trying to convert, from a textarea input ($_POST[\'content\']), all urls to link.

$content = preg_replace(\'!(\\s|^)((https?://)+[a-z0-9_./         


        
4条回答
  •  被撕碎了的回忆
    2020-12-16 02:14

    This has been done hundreds of times over before. On this page either m-buettner and glavić work fine although I like glivic's shorter expression.

    Here's a good php resource to do it: http://code.iamcal.com/php/lib_autolink/

    Repeats on Stackoverflow:

    • How do I linkify urls in a string with php?
    • PHP Linkify Links In Content

    Decent in-depth article: - http://buildinternet.com/2010/05/how-to-automatically-linkify-text-with-php-regular-expressions/

提交回复
热议问题