function validate_font_family($font_family, &$error_message)
    {
        $valid_match1 = '"Times New Roman",Georgia,Serif';
        $valid_match2 = '"Arial",Georgia,Serif';
        if(preg_match($valid_match1, $font_family) || preg_match($valid_match2, $font_family))
        {
            return true;
        }

        $error_message = "Invalid font family(" . $font_family . ").  Must be either ";
        $error_message .= $valid_match1 . " or " . $valid_match2;
        return false;
    }

The code is supposed to take a string, and if it is either of the following...

  • "Times New Roman",Georgia,Serif
  • "Arial",Georgia,Serif

it should return true. Otherwise, false.

I get the following error.

Warning: preg_match() [function.preg-match]: Unknown modifier ',' in C:\xampp\htdocs\MrLyons2\change_css.php on line 26

Warning: preg_match() [function.preg-match]: Unknown modifier ',' in C:\xampp\htdocs\MrLyons2\change_css.php on line 26

The comma in question appears to be the one right beforGeorgia, so I guess I need to escape those double quotes or something like that?

Recommended Answers

All 2 Replies

Member Avatar for diafol

You need to put delimiters (e.g. / or #) around your patterns:

$valid_match1 = '/"Times New Roman",Georgia,Serif/';
$valid_match2 = '/"Arial",Georgia,Serif/';

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.