Check text area for URLs with preg_match

172 views Asked by At

i found this code for checking a text area:

 if (strpos($textp, "http://") !== false ||
    ereg("(www.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9.]+)",$textp)){
    $textp = '';
  } else {

because ereg is depreacted I would like to replacy by preg_match instead. But if I replace I got an error according to \ So what I should I exactly edit to get the same result - no URLs or elements of that inn that text area.

1

There are 1 answers

0
Muhammad Haseeb Khan On BEST ANSWER

you just need to add / like

  preg_match("/(www.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9.]+)/",$textp)

please refer to preg_match