Regular expressions for unicode
Hi
I am trying a php code, I have a problem with the code, my code seems not to work with Unicode strings. I have posted a part of my code, can any one tell me why this is not working?
Code:
preg_replace('/\b'.$wd.'\b/ui', '<span class="bigger">$0</span>', $txt);
Please not that the variables $wd and $txt are unicode strings.
Re: Regular expressions for unicode
Hello
Quote:
Please not that the variables $wd and $txt are unicode strings.
You have not determined the values of the $wd and $txt. Can you write the values for the $wd and $txt strings? If you give the value of $wd and $txt , it would be better to solve your problem. Please post the values.
Re: Regular expressions for unicode
Hi
Quote:
You have not determined the values of the $wd and $txt. Can you write the values for the $wd and $txt strings?
Just for an example, assume
Code:
$word = test1;
$text = test2;
These are the unicode strings
Re: Regular expressions for unicode
Hi
Ok, the first thing you need to do is to convert your document to utf-8, alternatively you can put the following code in the HEAD tag in your page.
Quote:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Then you can try this simple code
Code:
$word = 'test1';
$text = 'test2';
echo preg_replace('/'.$wd.'/i', 'your replacement words', $txt);
Hope this may help you. if you did not solve the problem then do post again and we will find a solution for it.
Re: Regular expressions for unicode
Hi
Quote:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
The meta tag is already present there and the document is utf-8. Thanks for your code, but the is of no help for me, this is not what I was looking for. The main this is that I want to replace the words, which are not in any other word forms.Any simple example of this may be
Code:
"body" my be replace by "everybody"
Any help on this.