preg-matchereg

Check text area for URLs with preg_match


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.


Solution

  • you just need to add / like

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

    please refer to preg_match