problem with german Umlauts (äüö letters) in regular expressions

Status
Not open for further replies.

culebra99

New Member
Messages
1
Reaction score
0
Points
0
hi
i try to use regular expressions in php (e.g. $addressPattern = '/addressLines:\["[\w\s\düäöÄÖÜß-]+","[\w\s\düäöÄÖÜß-]+"\]/'; ) to get all addresse (with Umlauts as well), but it does not work : i get no addresses with Umlauts (äöü letters)

On my local machine(with german localization) it works fine.

may php.ini solve this problem?

Thanx in advance
 

Zubair

Community Leader
Community Support
Messages
8,766
Reaction score
305
Points
83
hi
i try to use regular expressions in php (e.g. $addressPattern = '/addressLines:\["[\w\s\düäöÄÖÜß-]+","[\w\s\düäöÄÖÜß-]+"\]/'; ) to get all addresse (with Umlauts as well), but it does not work : i get no addresses with Umlauts (äöü letters)

On my local machine(with german localization) it works fine.

may php.ini solve this problem?

Thanx in advance

You cannot edit or see php.ini on Free Account.
 
Last edited:

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
Use UTF-8 converters to use umlauts.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
1. Make sure you are saving the php script as UTF-8

2. With the current settings, PHP escapes quotes in form data. You have to use stripslashes() to remove the backslashes.

HTML:
<?php

$addressPattern = '/addressLines:\["[\w\s\düäöÄÖÜß-]+","[\w\s\düäöÄÖÜß-]+"\]/' ;
$testString = 'addressLines:["düäöÄÖÜß","düäöÄÖÜß"]' ; 
$hard_coded_result =  preg_match(  $addressPattern  ,    $testString   ) ;
$form_input_result = "\$_POST[ 'address' ] not set" ;
if( isset( $_POST[ 'address' ]  ) ){
  $form_input_result =   preg_match(  $addressPattern  ,     stripslashes( $_POST[ 'address' ]  ) )   ;
}
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
	<title>Testing</title>
</head>
<body>

<div>
<?php echo "Test string is <br /> $testString <br />" ; ?>
</div>

<div>
<?php echo "Hard  coded result is $hard_coded_result <br />" ; ?>
</div>

<div>
<?php echo "Form input result is $form_input_result <br />" ; ?>
</div>

<form action="" method="POST">
<input type="text" name="address" id="address" />
<input type="submit" value="Submit" />
</form>
</body>
</html>

seems to work for me. 0 is no match. 1 is a match.
 
Last edited:
Status
Not open for further replies.
Top