if ($field eq "comments") { # Remove any links (because they break URL to link conversion) $$field =~ s///isg; $$field =~ s/<\/A>//isg; # Extract any image links and add them to an array for safe-keeping, replace them with placeholders $image_database = 0; while ($$field =~ //) { $$field =~ s/()/\[My_Image=$image_database\]/iso; $images[$image_database] = $1; $image_database ++; } # If HTML is not allowed, strip any remaining HTML if ($allow_html != 1) { $$field =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs; } # Convert URL's and e-mail addresses to links (with regex) $$field =~ s/(((ht|f)tp):(\/\/)[a-z0-9%&_\-\+=:@~#\/.\?]+(\/|[a-z]))/$1<\/A>/isg; $$field =~ s/(^\W|\s)([a-z0-9_\-.]+\@[a-z0-9_\-]+\.[a-z]+)(.*?$)/$1$2<\/A>$3/mig; # Replace the image placeholders with their corresponding images $image_database = 0; while ($$field =~ /\[My_Image=(\d*)\]/) { $img_src = $images[$1]; $$field =~ s/\[My_Image=(\d*)\]/$img_src/iso; $image_database ++; } }