Jump to content

[SOLVED] preg different language not working


Recommended Posts

I am trying to convert a script which I originally wrote in English to work in another languages. I had a request to write the script in Romanian so that's what I have been trying to do. Your help would be greatly appreciated I'm really stuck with this one. I bet the solution is quite simple.

 

This is a very strange problem which I just don't quite understand and has got me really stumped.

 

My script works fine with the English language file but the Romanian one doesn't work. The strange thing is;

[*]The Romanian text "Nu ai nimerit" is matched but the others are not

[*]If i write $text['duel_pattern']="/(Nimerit: (Braţul drept|Umărul drept|Braţul stâng)\s-\s\d{1,} Puncte de viaţă)|(Nu ai nimerit)/"; into my main script file all the Romanian text is matched correctly

[*]The English file works with no problems

 

The only thing I can think of it's something to do with the different characters used in the Romanian text.

 

Here is my script:

 

en.php

<?php
// Declare all text strings,
// in English.
$GLOBALS['text'] = array ('duel_pattern' => "/(Strike:\s(Right arm|Right shoulder|Left arm|Left shoulder|Head)\s-\s\d{1,3}\sHP)|(No hit)|(Total health points\s-\s\d{1,3}\sHP)/");
?>

 

ro.php

<?php
// Declare all text strings,
// in Romania.
$GLOBALS['text'] = array ('duel_pattern' => "/(Nimerit: (Braţul drept|Umărul drept|Braţul stâng)\s-\s\d{1,} Puncte de viaţă)|(Nu ai nimerit)/");
?>

 

MainScript.php



<?PHP
// Now include the appropriate language file:
require_once "./lang/{$lang}.php";

//Parse hits in to an array
preg_match_all($text['duel_pattern'],$str,$hits);
?>

SOLVED IT

 

I noticed when that when I saved my ro.php file some of the special characters didn't save correctly. I thought this was a bit strange so tried saving them on my mainscript.php file and they saved correctly. Hmm, well I thought what could be causing this so checked the page properties(Dreamweaver) and seen that the mainscript.php file was encoded in UTF-8 while the ro.php file is encoded in Western European. I changed the encoding on the ro.php page to UTF-8 and problem solved ;D. All the special characters saved correctly and the preg worked how it was meant to.

 

Well like I first said it was to do with the different characters but was to do with there encoding.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.