0

I am using regexp in php I want to use use in regexp like thatI can use it but error is popupHow can solve this problem.please guide me.suppose here $url is dinamically changed like that

$preg_wurl = '/^'.$url.'/i';
    $wurl = preg_grep($preg_wurl,$urls);
$spreg_wurl = stripslashes($preg_wurl);
    echo '<h1>'.$spreg_wurl.'</h1>';

Error:

Warning: preg_grep() [<a href='function.preg-grep'>function.preg-grep</a>]: Unknown modifier '/' in C:\wamp\www\PHP\get website link.php on line 33
user1752627
  • 2,527
  • 2
  • 15
  • 10
  • Might below post will help you to find solution: http://stackoverflow.com/questions/3578671/unknown-modifier-g-in-when-using-preg-match-in-php – Yuvraj Feb 20 '13 at 05:50

2 Answers2

0

You can use some delimiter other than slashes to specify a regex, such as "!/!" to match any slash. Note that I'm using ! instead of / to delimit my regex.

Ian McMahon
  • 1,660
  • 11
  • 13
  • here is many things which are to strips like **slashes /** **dots .** and **comloms :** – user1752627 Feb 20 '13 at 05:51
  • Use a character class to include or exclude entire ranges of characters, such as `/[^a-zA-Z0-9 ]/` to strip anything but alphanumeric or space. – Ian McMahon Feb 20 '13 at 05:53
0

Use preg_quote() function to escape regular expression characters try$preg_wurl = '/^'.preg_quote($url, '/').'/i';

Hexogen
  • 393
  • 1
  • 4
  • 12