?
Solved

Preg_Match and special characters

Posted on 2012-09-20
2
Medium Priority
?
811 Views
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"?
0
Comment
Question by:rgranlund
  • 2
2 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38419193
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.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1000 total points
ID: 38419212
Ahh, thought I had an example... Sure enough!
http://www.laprbass.com/RAY_temp_array007.php
<?php // RAY_temp_array007.php
error_reporting(E_ALL);
echo "<pre>";

// SET WESTERN CHARACTER SET - SEE http://dev.w3.org/html5/markup/meta.charset.html
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";
    }
    else
    {
        echo " NO GOOD";
    }
}

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

839 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