regexpreg-replaceereg-replace

Change ereg_replace to preg_replace


How would I change

$output = ereg_replace("<script.*</script>", "", $output);

to preg?

 I tried $output = preg_replace("/<script.*</script>/", "", $output);

Thanks

EDIT: Sorry, messed up formatting


Solution

  • If you use / as the delimiter, you must escape every occurence of / within the pattern, or its recocnized as delimiter itself and everthing following will be used as modifiers (which will probably fail).

    "/<script.*<\/script>/"
    

    or you make your life easy and just choose a different delimiter. I prefer ~, because it occurs in patterns quite infrequent

    "~<script.*</script>~"
    

    Update: See comments for the description, what happens here

    "~<script.*</script>~siU"