• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 754
  • Last Modified:

preg_replace a specific character accent

I know the code works as per the demo below (the array is an array of $_POST[])
if I use the uncommented one it repace the "a" with é then correct values are inserted in DB and echoed as supposed to (utf8)
but when I try with the accentuated letter it does not find that accentuated letter, why would preg_match not find an accent?
what's going on?
thanks
$txt_fields	= Array ('fav_snack', 'fav_appetizer', 'fav_soup', 'fav_salad', 'fav_sandwich', 'fav_seafood', 'fav_pasta', 
										'fav_accompaniment', 'fav_veg_entree', 'fav_meat_entree', 'fav_dessert');
	foreach ($txt_fields as $fld) {//echo $fld;
	//	if (isset($_POST[$fld])) { $_POST[$fld] = preg_replace('/[é]+/i','é',$_POST[$fld]); echo $_POST[$fld];}
		if (isset($_POST[$fld])) { $_POST[$fld] = preg_replace('/[a]+/i','é',$_POST[$fld]); echo $_POST[$fld];}
}

Open in new window

0
array007
Asked:
array007
  • 2
  • 2
  • 2
2 Solutions
 
Shinesh PremrajanEngineering ManagerCommented:
The code seems working fine, while echoing you can check using the function htmlentities($fld) instead of just $fld.

Hope this helps
0
 
array007Author Commented:
Well I found it
in the preg [é] is not correct it works if it is as follow: [\é]
0
 
Ray PaseurCommented:
I think you may have an encoding issue here.  The accented characters in the Western languages are often confused with the control characters that form a part of UTF-8.  You might want to have a look at this article and decide whether you really need UTF-8 or not.
http://www.joelonsoftware.com/articles/Unicode.html
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
array007Author Commented:
Thanks Ray, very good reading, even after eight years!
0
 
Ray PaseurCommented:
Yeah, Joel gets it right almost all the time!
0
 
Shinesh PremrajanEngineering ManagerCommented:
Yes thanks Ray, for the superb piece of information, its really worth a reading... kul..dude..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now