Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 15-12-2009
Member
 
Join Date: Apr 2008
Posts: 240
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.
Reply With Quote
  #2  
Old 15-12-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
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.
Reply With Quote
  #3  
Old 15-12-2009
Member
 
Join Date: Apr 2008
Posts: 240
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
Reply With Quote
  #4  
Old 15-12-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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.
Reply With Quote
  #5  
Old 15-12-2009
Member
 
Join Date: Apr 2008
Posts: 240
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Regular expressions for unicode"
Thread Thread Starter Forum Replies Last Post
What are an Expressions in PHP? michaels Software Development 5 05-03-2010 05:44 AM
What is the unicode in PHP V5.3 Abigail101 Software Development 5 20-02-2010 12:50 AM
Regular Expressions on the Contents of a File samualres Software Development 4 19-02-2010 10:30 PM
Question on regular expressions Logan 2 Software Development 5 12-02-2010 04:21 AM
Regular Expressions in Java Ash maker Software Development 5 03-02-2010 04:42 AM


All times are GMT +5.5. The time now is 03:50 AM.