Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to make it support Chinese?

Posted on 2004-04-14
1
Medium Priority
?
193 Views
Last Modified: 2006-11-17
Here is the program segment:
$bool_var=preg_match("/\b$search_item\b/i", $contents);


$search_item is the word I need to search in the $contents
It returns TRUE when $contents contains the word we want to search

in this case:
if I search for apple
apple is true, but apples is not true

but Why can't I search for Chinese words?
0
Comment
Question by:cmkpl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
Fataqui earned 400 total points
ID: 10824533
Hi

If you are using $var(s) inside your preg_match search regex string then you need to make the function understand that your $var(s) are a reference to another value! Maybe you might understand what I mean so I will give you an example....

If I was to do this................ ECHO(s) -> NOT FOUND

<?

$content = 'just some text that contains the word ¥¢¥Ã¥×¥ë¥Ñ¥¤ <- "apple". Can pre_match find it?';

$search = '¥¢¥Ã¥×¥ë¥Ñ¥¤';

if ( preg_match ( '!$search!', $content ) )
{

echo 'FOUND';

}
else
{

echo 'NOT FOUND';

}


?>



The function would echo "NOT FOUND", because it is not looking for the value of $search but the literally word 'search'. Now because you are searching different character set you should 'quote' the value passed to your preg_match function! This way the function will work, example....


If I was to do this................ ECHO(s) -> FOUND

<?

$content = 'just some text that contains the word ¥¢¥Ã¥×¥ë¥Ñ¥¤ <- "apple". Can pre_match find it?';

$search = '¥¢¥Ã¥×¥ë¥Ñ¥¤';

if ( preg_match ( '!' . preg_quote ( $search ) . '!', $content ) )
{

echo 'FOUND';

}
else
{

echo 'NOT FOUND';

}


?>


Fataqui!

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question