vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   [SOLVED] Arabic encoding with preg_match_all (https://vborg.vbsupport.ru/showthread.php?t=315446)

omardealo 11-16-2014 12:20 AM

[SOLVED] Arabic encoding with preg_match_all
 
HELLO ,

i try discovery of banned words when users posted new post , but i have a problem only Only the discovery of English words, I think that the problem is in the Arabic language encoding , I tried to solve the problem by
PHP Code:

iconv("windows-1256""utf-8",$string ); 

but don't work , Are there any suggestions ?


Code:

$wordss = "هالو|مرحبا|google.com";
$bwords = explode("|", $wordss); 
//$string = $vbulletin->GPC['message']; 
$string = 'BLA BLA مرحبا BLA BLA google.com BLA BLA BLA '; 
$matchFound = preg_match_all( 
                "/\b(" . implode($bwords,"|") . ")\b/i", 
                $string, 
                $matches 
              ); 
$words = array_unique($matches[0]); 
print_r($words);


output : google.com
but Must be : google.com,مرحبا

kh99 11-16-2014 01:40 AM

Maybe try putting a u at the end of your pattern string:
Code:

"/\b(" . implode($bwords,"|") . ")\b/iu"
to tell it to use unicode strings.

omardealo 11-16-2014 02:09 AM

Quote:

Originally Posted by kh99 (Post 2522916)
Maybe try putting a u at the end of your pattern string:
Code:

"/\b(" . implode($bwords,"|") . ")\b/iu"
to tell it to use unicode strings.

yes sir , i try this pattern already
i change /i to /iu
and try it on Different places
- on online external php file by [/iu] only - > works good
- on localhost vbulletin plugin by [/i] only - > works good
but ..
- on localhost external php file - > don't work
- on online vbulletin plugin - > don't work

so .. i Become confused :erm: , i don't know what's the wrong

--------------- Added [DATE]1416112678[/DATE] at [TIME]1416112678[/TIME] ---------------

UPDATE :
when i convert php files to encoding ANSI , Results appear in Arabic by pattern "/\b(" . implode($bwords,"|") . ")\b/i"
but on plugin how i solve this problem ?

kh99 11-16-2014 01:56 PM

I can't get it to work on my test system either, so I'm afraid I'm stumped. I googled to try to find an answer, but the only thing i found was something that mentioned that it's possible that some versions of php don't handle UTF-8 matching correctly.

omardealo 11-16-2014 02:15 PM

Quote:

Originally Posted by kh99 (Post 2522972)
I can't get it to work on my test system either, so I'm afraid I'm stumped. I googled to try to find an answer, but the only thing i found was something that mentioned that it's possible that some versions of php don't handle UTF-8 matching correctly.

yeah I also looked very much on google, thank you
But I do not think this is the reason [php versions] , because the code work well in an external file on the same site withot encoding it but on vb plugin don't work .
anyway , can i do what i want by another way ? matching banned words and print it with no problem with the Arabic words .

--------------- Added [DATE]1416157331[/DATE] at [TIME]1416157331[/TIME] ---------------

UPDATE :
I FOUND THE Solution :

\b detects word boundaries, remove them to get a regular match.


JUST USE pattern

Code:

"/(" . implode($bwords,"|") . ")/i "
THANX , kh99


All times are GMT. The time now is 12:21 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00960 seconds
  • Memory Usage 1,730KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete