I am trying to convert, from a textarea input ($_POST[\'content\']
), all urls to link.
$content = preg_replace(\'!(\\s|^)((https?://)+[a-z0-9_./
Let me suggest something less straight forward: split the input text into the html and non-html parts, then process the non-html parts with your regexp combining the text back into one piece. Smth. like:
)/Ums', $_POST['content'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$result = '';
foreach ($chunks as $chunk) {
if (substr($chunk,0,1) != '<') {
/* do your processing on $chunk */
}
$result .= $chunk;
}
Some additional advices: