Preg_Match and special characters

Posted on 2012-09-20
Last Modified: 2012-09-20
How do I use preg_match and allow a special character?  Specifically

Open in new window

but when it is typed in with the apostrophe above the "e"?
Question by:rgranlund
    LVL 107

    Expert Comment

    by:Ray Paseur
    Put the character into the regular expression - no special handling needed.

    If you want to show me some data in context I'll show you how it might work.
    LVL 107

    Accepted Solution

    Ahh, thought I had an example... Sure enough!
    <?php // RAY_temp_array007.php
    echo "<pre>";
    echo "<meta charset=ISO-8859-1>";
    // TEST DATA
    $arr = array
    ( 'Hello World'
    , 'Héllo World'
    , 'Hello World!'
    foreach ($arr as $str)
        echo PHP_EOL . $str;
        if (!preg_match("/[^a-z0-9é,\.\-\s]+/i", $str))
            echo " OKAY";
            echo " NO GOOD";

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now