Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Japanese Character

Status
Not open for further replies.

uniopp

Technical User
Oct 7, 2001
152
JP
I have the following code in a form submission and it jumbles my Japanese text -

PHP:
$name = ucfirst(strtolower(strip_tags($_REQUEST["name"])));

When I replaced it with the following my Japanese text is ok -
PHP:
$name=$_REQUEST['name'];

The following field also gives me some jumbled text SOMETIMES -

PHP:
$content = strip_tags($_REQUEST['content']);

What is the best way to handle the Japanese text and strip out anything that is not needed (not really sure what that might be) but keep the text from being jumbled.
I guess it has something to do with Japanese characters being 2 bytes per character.

Thanks
 
Hi

I would try to use Multibyte String Functions where available :
PHP:
[gray]// instead of[/gray]
[navy]$name[/navy] [teal]=[/teal] [COLOR=orange]ucfirst[/color][teal]([/teal][COLOR=orange]strtolower[/color][teal]([/teal][navy]$_REQUEST[/navy][teal][[/teal][i][green]"name"[/green][/i][teal]]));[/teal] 
[gray]// try[/gray]
[navy]$name[/navy] [teal]=[/teal] [COLOR=orange]mb_strtoupper[/color][teal]([/teal][COLOR=orange]mb_substr[/color][teal]([/teal][navy]$_REQUEST[/navy][teal][[/teal][i][green]"name"[/green][/i][teal]],[/teal] [purple]0[/purple][teal],[/teal] [purple]1[/purple][teal])) .[/teal] [COLOR=orange]mb_strtolower[/color][teal]([/teal][COLOR=orange]mb_substr[/color][teal]([/teal][navy]$_REQUEST[/navy][teal][[/teal][i][green]"name"[/green][/i][teal]],[/teal] [purple]1[/purple][teal])),[/teal]

[tt]strip_tags()[/tt] is a harder problem, but if you not need its 2[sup]nd[/sup] parameter anyway, then you could try to use [tt]preg_replace()[/tt] with [tt]u[/tt] modifier :
PHP:
[gray]// instead of[/gray]
[navy]$content[/navy] [teal]=[/teal] [COLOR=orange]strip_tags[/color][teal]([/teal][navy]$_REQUEST[/navy][teal][[/teal][i][green]'content'[/green][/i][teal]]);[/teal]
[gray]// try[/gray]
[navy]$content[/navy] [teal]=[/teal] [COLOR=orange]preg_replace[/color][teal]([/teal][i][green]'/<.*?>/u'[/green][/i][teal],[/teal] [i][green]''[/green][/i][teal],[/teal] [navy]$_REQUEST[/navy][teal][[/teal][i][green]'content'[/green][/i][teal]]);[/teal]


Feherke.
feherke.github.io
 
Thanks for your help.
What are the two examples I posted actually doing to the stored values and is there anything wrong with using just -
PHP:
$name=$_REQUEST['name']; 
$name=$_REQUEST['content'];
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top