Results 1 to 5 of 5

Thread: Regular expressions for unicode

  1. #1
    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.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Regular expressions for unicode

    Hello
    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.

  3. #3
    Join Date
    Apr 2008
    Posts
    240

    Re: Regular expressions for unicode

    Hi
    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

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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.
    <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.

  5. #5
    Join Date
    Apr 2008
    Posts
    240

    Re: Regular expressions for unicode

    Hi
    <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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,101,379.93480 seconds with 17 queries